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
 Set A Foreign Key

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2011-09-21 : 09:21:25

Hi,

I have a SQL Table on my database called dbo.TblPracticeConsent, it has 3 fields
cid (PK) - datatype(numerical(18,0))- Auto increment
xstart - datatype (datetime)
pracid - datatype (numerical (18,0))


Now, am suppose to make pracid as a FK, I dont see the option from the designer..

How can I make pracid a FK?

Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 09:31:20
use

ALTER TABLE... ADD CONSTRAINT...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

fghamdi
Starting Member

1 Post

Posted - 2011-09-21 : 09:43:12
ALTER TABLE TblPracticeConsent
ADD FOREIGN KEY (pracid)
REFERENCES
TargetTable(TargetPriamryKey)

---

FK has to be linked to a primary key in another table.
You can use the designer in different ways.
After you click on the plus sign of the any table,you get a few folders and one of them is keys
you can click right mouse and add a new FK.

You may create a diagram by draging or drawing a line from the target filed, and pull it to the target primary key that you want it to be connected to Fk.



Go to Top of Page
   

- Advertisement -