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.
| Author |
Topic |
|
joldham
Wiseass Yak Posting Master
300 Posts |
Posted - 2002-03-27 : 16:28:19
|
| I am trying to add a FK constraint on an existing column in a table.Is there a way to do this without dropping and re-creating the table?Jeremy |
|
|
JamesT
Yak Posting Veteran
97 Posts |
Posted - 2002-03-27 : 16:33:47
|
| ALTER TABLE TBL_NAME ADD CONSTRAINT [PK_TBL_NAME] PRIMARY KEY NONCLUSTERED (COLUMN_NAME)Something like that.Oops. Choose the wrong example.Edited by - JamesT on 03/27/2002 16:58:15 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-03-27 : 16:48:21
|
| Close - you should find it by looking at alter table statement anyway.Something more likealter table <tbl> add constraint <name> foreign key (fld1,fld2) references <tbl> (fld1,fld2)==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-03-27 : 17:31:18
|
JamesT.Beginners mistake - add to your post total by correcting yourself in another post rather than editing the previous one.Like this (thanks) .==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
joldham
Wiseass Yak Posting Master
300 Posts |
Posted - 2002-03-27 : 19:36:06
|
| Thanks guys. I looked in BOL and I guess I misinterpreted what it said. From what I could tell, you had to add a new column to do this. I guess after looking at the code provided, I will go back and look at BOL to see what they really meant.Jeremy |
 |
|
|
|
|
|