Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have one table having one primary key

create table PSM.dbo.Prospect(Prospect_ID int primary key,Prospect_Name varchar(50),Prospect_Source varchar(50),Prospect_Products_Services varchar(50) );


2nd table having foreign key and one primary key

create table PSM.dbo.conversion(Prospect_ID int references Prospect(Prospect_ID)  ,Customer_ID int primary key,Customer_Name varchar(50),Customer_Products_Services varchar(50));



now i want 2nd table having propect_id should also have unique value(no duplication).so hw can i do this
Posted

Put a unique constraint on that field of the 2nd table. Thus, even though it will be a Foreign Key, the constraint will make sure that no duplication happens at the time of insertion. Any repeat would throw a constraint error.

Read here:
http://msdn.microsoft.com/en-us/library/ms191166.aspx[^]
http://msdn.microsoft.com/en-us/library/aa933091%28v=sql.80%29.aspx[^]
http://www.w3schools.com/sql/sql_unique.asp[^]
 
Share this answer
 
Add a Unique key to it

SQL
ALTER TABLE PSM.dbo.conversion
ADD UNIQUE (propect_id)


Hope it helps.......
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900