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 |
Arijit
Starting Member
25 Posts |
Posted - 2006-01-16 : 06:57:40
|
Hi,I have a doubt on Primary key column and not null unique column.What is the difference between this?Whatever I think Primary Key by default creates Clustered Index and Unique Key creates Nonclustered Index. Other than this I don't find any other diff. Can anyone say anything more on this?RegardsArijit Chatterjee |
|
dsdeming
479 Posts |
Posted - 2006-01-16 : 08:22:08
|
A primary key must be unique. There may be several columns in a table which all contain unique values, and while they may each have a unique index, only one can be the primary key. PKs are usually clustered (though they are not required to be), which just means that the data is stored on the data pages in index order. Searching a clustered index is faster than searching a nonclustered one because when you search a nonclustered index, you search through the index pages to get pointers to the data pages that are then used to retrieve the data. With a clustered index, you search the data pages directly.Dennis |
 |
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2006-01-16 : 09:08:29
|
Just to AddThere can be only one Primary Key in a table (Although more than one column can constitue a primary key ,called "Composite Primary Key) You can have multiple unique keys in a tablePrimary key can not have NULL values while one NULL values is allowed for Unique Key Column.. |
 |
|
Arijit
Starting Member
25 Posts |
Posted - 2006-01-16 : 23:44:17
|
Hi All,Thanks for your responses.As I told in my query,If the Unique Column is also defined as NOT NULL also then we can say that Unique column is not storing any null values. And also if we define that column as clustered then what is the difference with it with any Primary Key Column?RegardsArijit Chatterjee |
 |
|
Arijit
Starting Member
25 Posts |
Posted - 2006-01-16 : 23:53:18
|
Hi All,I am giving a Create Table Statementcreate table t1(val1 int primary key ,val2 int unique clustered not null)Here is not the val2 column acting as Primary Key Column even though it is not defined as Primary Key.RegardsArijit Chatterjee |
 |
|
|
|
|