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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CLUSTERED

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-10-17 : 20:34:15
Hi,

What is the difference between:

create table dbo.Users
(
UserID uniqueidentifier not null
constraint PK_User primary key,
Email nvarchar(200) null,
...


and


create table dbo.Users
(
UserID uniqueidentifier not null
constraint PK_User primary key CLUSTERED,
Email nvarchar(200) null,
...


Thanks,
Miguel

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-17 : 21:21:25
not much... PK creates clustered index by default..so you are just saying the obvious in your second script..

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-10-18 : 08:02:49
Hi,

So I have the following:

create table dbo.PostsTags
(
PostID uniqueidentifier not null,
TagID uniqueidentifier not null,
constraint PK_PostsTags
primary key CLUSTERED (PostID, TagID),
constraint FK_PostsTags_Posts
foreign key(PostID)
references dbo.Posts(PostID)
on delete cascade,
constraint FK_PostsTags_Tags
foreign key(TagID)
references dbo.Tags(TagID)
on delete cascade
)


Can I remove the CLUSTERED to?

Thanks,
Miguel
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-18 : 12:19:19
quote:
Originally posted by shapper

Hi,

So I have the following:

create table dbo.PostsTags
(
PostID uniqueidentifier not null,
TagID uniqueidentifier not null,
constraint PK_PostsTags
primary key CLUSTERED (PostID, TagID),
constraint FK_PostsTags_Posts
foreign key(PostID)
references dbo.Posts(PostID)
on delete cascade,
constraint FK_PostsTags_Tags
foreign key(TagID)
references dbo.Tags(TagID)
on delete cascade
)


Can I remove the CLUSTERED to?

Thanks,
Miguel



Yep. you can remove the word "clustered" and SQL Server will still create a clustered index on the PK. You need to specify only if you want a non-clustered index on PK. otherwise its just redundant.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -