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 |
|
rypi
Yak Posting Veteran
55 Posts |
Posted - 2011-01-29 : 15:25:17
|
| Is it possible to make a column unique based off a foreign key?For example, lets say there is a table like this:ID FKID UniqueCol1 3 Test2 3 Test13 4 Test14 4 Test2The "UniqueCol" can have duplicate entries only if it's FKID is different. So there could be multiple 'Test1' entries as long as there is only 1 'Test1' entry per FKID.Is this possible?Thanks in advance. |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-29 : 15:42:07
|
| ALTER TABLE <tablename> ADD CONSTRAINT <constraint name> UNIQUE (FKID, UniqueCol)--Gail ShawSQL Server MVP |
 |
|
|
rypi
Yak Posting Veteran
55 Posts |
Posted - 2011-01-31 : 11:05:39
|
| Thanks GilaMonster! |
 |
|
|
|
|
|