sql - Specify a Composite Foreign Key -


i'm trying create foreign key out of 2 values in 2 different tables, pointers appreciated!

below code using :

create table [dbo].[employeeunsetzone](     [employeeid] [char](2) null,     [zoneofficeid] [int] not null,     [zoneid] [char](4) null     constraint employeeunsetzone_employeefk foreign key([employeeid],[zoneid])     references [employee]([id]), [zonebyoffice]([id]) ) 

i'd use:

create table [dbo].[employeeunsetzone](   [employeeid] [char](2) null,   [zoneofficeid] [int] not null,   [zoneid] [char](4) null,   primary key ([employeeid], [zoneid]),   constraint fk_employeeid foreign key([employeeid]) references [employee]([id]),   constraint fk_zoneid foreign key([zoneid]) references [zonebyoffice]([id]) ) 

the primary key stop duplicates, , setup clustered key 2 columns make searching against better.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -