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)
 Sequential Guid

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-10-31 : 12:45:41
Hello,

I am creating a new database and I was advised to use Sequential Guids.
I was reading some information and, as far as I understood, I can use NEWSEQUENTIALID. This can be used when I have a uniqueidentifier column as the key of a clustered index to avoid fragmentation during insert.

Ok, so I use NEWSEQUENTIALID instead of NEWID.

But I will use LINQ most of the time instead of Stored Procedures.

So can I specify in my tables scripts to use Sequential Guids when, for example, a record is created?

Here is a part of my code:

-- Blogs ...
create table dbo.Blogs
(
BlogID uniqueidentifier not null
constraint PK_Blog primary key clustered,
Title nvarchar(400) null,
Description nvarchar(2000) null,
CreatedDate datetime null
)

-- Posts ...
create table dbo.Posts
(
PostID uniqueidentifier not null
constraint PK_Post primary key clustered,
BlogID uniqueidentifier not null,
AuthorID uniqueidentifier not null,
Title nchar(1000) null,
Body nvarchar(max) null,
UpdatedDate datetime not null,
IsPublished bit not null,
constraint FK_Posts_Blogs
foreign key(BlogID)
references dbo.Blogs(BlogID)
on delete cascade,
constraint FK_Posts_Users
foreign key(AuthorID)
references dbo.Users(UserID)
on delete cascade


Thanks,
Miguel

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-31 : 12:48:13
can't you specify a default value?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-10-31 : 13:01:23
you mean:

create table dbo.Blogs
(
BlogID uniqueidentifier not null
constraint PK_Blog primary key clustered
default NewSequentialID(),
Title nvarchar(400) null,
Description nvarchar(2000) null,
CreatedDate datetime null
)


right?

Thanks,
Miguel
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-31 : 13:07:12
yes.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -