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 |
|
royv
Constraint Violating Yak Guru
455 Posts |
Posted - 2002-01-09 : 20:39:35
|
| I am interested to know which constraint would be better from a speed perspective and a size/cost perspective. As far as I can tell, they both create indexes, but I do know that the primary key constraint does more work, so maybe its size(cost) / speed would be worse when compared to a unique constraint? I am leaning towards unique constraints over primary keys, but would really really like to know in general which is better. Been over BOL pretty thoroughly, they do give some small scenarios about which would be better in specific situations, but it did not give a strong yes or no towards unique or primary key constraints. Looking foward to replies.*************************Just trying to get things done |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-01-10 : 00:12:58
|
| The First thing you should remember is in a Unique constraint a Null value is allowed.Follow this link http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=11768.This is what BOL has to say about Primary key and Unique Keys.A column, or combination of columns, that is not the primary key. Multiple UNIQUE constraints can be defined on a table, whereas only one PRIMARY KEY constraint can be defined on a table. A column that allows null values. UNIQUE constraints can be defined on columns that allow null values, whereas PRIMARY KEY constraints can be defined only on columns that do not allow null values. IMHO Primary key should be faster, but not sure about the Cost. if you want a field to be unique without containing any null values and want to have relationship's then i would recommend you to go for Primary key. though unique key supports relationship ,but not that suitable coz it can contain a null value.HTH----------------------------Anything that Doesn't Kills you Makes you Stronger |
 |
|
|
royv
Constraint Violating Yak Guru
455 Posts |
Posted - 2002-01-10 : 12:05:44
|
| Thanks Nazim, appreciate the response. I think I'll stick with primary keys for now.*************************Just trying to get things done |
 |
|
|
|
|
|
|
|