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
 Error Message when creating table

Author  Topic 

Claudine
Starting Member

1 Post

Posted - 2014-03-23 : 02:16:49
I am trying to create tables in SQL but this message keep coming up and I can't seems to figure what is wrong can someone please help am stock here the message is

Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'Donation' that match the referencing column list in the foreign key 'fk_Branch_bloodType'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

The table name affected is Purchase ,below are the tables the table Donation is created but purchase can't

create table Donation
(
Donation_Code varchar (5) primary key,
Blood_Type varchar (4) not null,
Date_Recd date not null,
Date_Of_Expiry date not null,
Purpose varchar (30),
Units integer ,
Donor_Id varchar (7),
Branch_Code varchar (10),
constraint fk_donor foreign key ( Donor_Id) references Donor(Donor_Id),
constraint fk_branch foreign key ( Branch_Code) references Branch(Branch_Code)
)

Create table Purchase
(
Purchase_code varchar (4) primary key,
Purchase_Date Date,
HCP_Code varchar(8),
Cost money,
Num_of_Unit integer,
Blood_Type varchar (4) not null,
Branch_Code varchar (10),
Donation_Code varchar (5),
constraint fk_Branch_bloodType foreign key (Blood_Type) references Donation(Blood_Type),
constraint fk_Purch_branch foreign key (Branch_Code) references Branch(Branch_Code)

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-03-23 : 18:06:51
The error message is telling you that you cannot create a foreign key constraint that points to Blood_type on Donation table because Blood_Type column in Donation table does not have a uniqueness constraint on it. See here for relevant documentation: http://technet.microsoft.com/en-us/library/ms175464(v=sql.105).aspx
Go to Top of Page
   

- Advertisement -