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)
 Create Tables

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-07-28 : 09:00:29
Hello,

I am creating the following related tables as follows:


create table Tags
(
ID uniqueidentifier not null
constraint PK_Tag primary key clustered,
[Name] nvarchar(100) null
) -- Tags

create table Articles
(
ID uniqueidentifier not null
constraint PK_Article primary key clustered,
Body nvarchar(max) null,
Created datetime null,
Excerpt nvarchar(max) null,
Published bit null,
Title nvarchar(400) null,
Updated datetime null
) -- Articles

create table ArticleTags
(
ArticleID uniqueidentifier not null,
TagID uniqueidentifier not null,
constraint PK_ArticleTags
primary key clustered (ArticleID, TagID),
constraint FK_ArticleTags_Articles
foreign key(ArticleID)
references Articles(ID)
on delete cascade,
constraint FK_ArticleTags_Tags
foreign key(TagID)
references Tags(ID)
on delete cascade
) -- ArticleTags


Should I use clustered primary key on Tags and Articles?
What other improvements would you make to my code?

Thanks,
Miguel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-07-28 : 13:53:04
We can't really comment on what should be the clustered index on a table as that is based upon the data and your queries. I for one wouldn't use a uniqueidentifier as the PK.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-07-28 : 14:11:13
quote:
Originally posted by tkizer

We can't really comment on what should be the clustered index on a table as that is based upon the data and your queries.



Basically I am using LINQ on the queries.
And what you mean about that?

As the UniqueIdentifier I need to use it on this.
Go to Top of Page
   

- Advertisement -