Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to set a foreign key

Author  Topic 

roshana
Starting Member

31 Posts

Posted - 2009-12-01 : 03:37:09
Hi All,
How to set foreign key to a table which is having multi value primary key

eg :
Table1

zyz pk
xyz pk
abc
bcd

Table2
zyz fk
xyz fk
asd PK
dfg

in Table1 zyz,xyz are the primary keys .In Table2 asd is Primary key and we have to set a relation with Table1 for zyz,xyz how we can do it

Thanks
Roshana

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-01 : 09:16:13
[code]
create table t1 (
a int not null,
b int not null,
c char(1),
Constraint PK_t1 Primary Key (a, b)
);
GO

Create Table t2 (
a int,
b int,
c int,
Constraint FK_t2_t1 Foreign Key (a, b)
References t1 (a, b)
);
GO[/code]
Go to Top of Page
   

- Advertisement -