Friday, March 9, 2012

How to get Reference from CompositePrimaryKey field ??...

I have one table nameMagazine_Details,it has a composite primary key

Create table Magazine_Details(MagazineTitlevarchar(60),MagazineTypevarchar(20),IssueTypevarchar(25),IssueNumbervarchar(10),Qntyint,Qnty_in_Handint,[Date]datetimeconstraint PK_Magazine_Details_Compositeprimary key(MagazineTitle,IssueNumber))

Another table isMagazine_Issued and i want reference from Magazine_Details table. but i am auable to create foreign key constaraint inMagazine_Issued table.

create table Magazine_Issued(Member_IDvarchar(100),MagazineTitlevarchar(60)references Magazine_Details(MagazineTitle),IssueNumbervarchar(10)references Magazine_Details(IssueNumber),IssueDatedatetime,Magazine_Statusvarchar(10))

Hi,

If you need to create the foreign key constraint, you also need to add the CONSTRAINT clause and constraint name.

create table Magazine_Issued
(
Member_ID varchar(100),
MagazineTitle varchar(60) CONSTRAINT FK_MagazineTitle_Details_Issued FOREIGN KEY (MagazineTitle) references Magazine_Details(MagazineTitle),
IssueNumber varchar(10) CONSTRAINT FK_IssueNumber_Details_Issued FOREIGN KEY (IssueNumber) references Magazine_Details(IssueNumber),
IssueDate datetime,
Magazine_Status varchar(10)
)

|||

after trying to create Magazine_Issued Table following error comes.

primary or candidate keys in the referenced table 'Magazine_Details' that match the referencing column list in the foreign key 'FK_MagazineTitle_Details_Issued'.

Could not create constraint. See previous errors.

|||

miazaidi:

after trying to create Magazine_Issued Table with above script following error comes.

primary or candidate keys in the referenced table 'Magazine_Details' that match the referencing column list in the foreign key 'FK_MagazineTitle_Details_Issued'.

Could not create constraint. See previous errors.

No comments:

Post a Comment