Monday, March 19, 2012

differnce between a column that s a primary key and a column that s a "key/index with Isuni

Hi,

Please, What s the differnce between a column that s a primary key and a column that s a "key/index with Isunique=true"?

Thanks a lot.

EDIT

A Primary cannot be Null but Unique key can be Null. Check the links below for the documentation.

http://msdn2.microsoft.com/en-us/library/ms181043.aspx

http://msdn2.microsoft.com/en-us/library/ms191166.aspx

|||

Another difference is that if you use a UNIQUE constraint as a target for a foreign key reference you must explicitly reference the columns.

For instance, if you have a table "TableA" that has a primary key "TableA_PKCol", you can target that as a foreign key from table "TableB" with something like:

Code Snippet

Alter table TableB

add constraint FK_TableB__TableA

foreign key (TabkeA_PKCol)

references TableA

However, if you have a table "TableJ" that has a unique key "TableJ_UQCol", you must explicitly name that column to target this column as a foreign key target from "TableK" with something like:

Code Snippet

Alter table TableK

add constraint FK_TableK__TableJ

foreign key (TableJ_UQCol)

references TableJ (TableJ_UQCol)

No comments:

Post a Comment