A
A
Andrey Romanyuk2017-05-30 08:46:04
SQL Server
Andrey Romanyuk, 2017-05-30 08:46:04

What is UC_Person in this SQL UNIQUE Constraint example?

c5c4458f0a394b7880848bfef46f863f.JPG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2017-05-30
@BLek2

What is UC_Person in this SQL UNIQUE Constraint example?
The ID, LastName pair is unique.
In general, this is an incorrect architecture - the ID counter must be unique, for example:
...
[ID] [int] IDENTITY(1,1) NOT NULL
...
CONSTRAINT [PK_Persons] PRIMARY KEY CLUSTERED ( [ID] ASC )
...

Yes, I forgot, another architectural mistake: you need to specify not the age, but the date of birth. And then in a year your data will lose relevance. It is possible like this:
...
  [BirthDay] [datetime] NULL,
  [DeathDay] [datetime] NULL,
        [Age] [int] NULL AS DATEDIFF( Year, BirthDay, ISNULL( DeathDay, GETDATE())) 
         + ( SIGN ( DATEDIFF ( DAY, BirthDay, DATEADD ( YEAR, YEAR( BirthDay ) 
         - YEAR( ISNULL( DeathDay, GETDATE()) ), ISNULL( DeathDay, GETDATE())))) - 1 ) / 2
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question