Sequential Guids

Last post 12-20-2007 4:44 PM by Nick Kusters. 2 replies.

Sort Posts:

  • Sequential Guids

    10-31-2007, 12:56 PM
    • Loading...
    • shapper
    • Joined on 11-28-2004, 9:15 PM
    • Posts 2,011

     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?
     
    And am I right when using Sequential Guids?

    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
  • Re: Sequential Guids

    10-31-2007, 2:16 PM
    Answer
    • Loading...
    • FerVitale
    • Joined on 02-16-2007, 8:29 PM
    • Buenos Aires
    • Posts 184

     Hi Miguel,

                     You are able to use the DEFAULT option set to NEWSEQUENTIALID() function for the BlogID and PostID column. I've read that on SqlServer Books on line.

                       I hope it helps.

     

    Regards,

    Fernando
     


     

  • Re: Sequential Guids

    12-20-2007, 4:44 PM
    • Loading...
    • Nick Kusters
    • Joined on 12-20-2007, 4:37 PM
    • The Netherlands
    • Posts 239

    By Default, the property "Auto Generated Value" is not set, changing this fixes your problem.

     More info can be found here.

    Also visit my website.

    Once your questions have been answered, remember to mark the question as answered, this rewards the people helping you and helps others to move on to the next unanswered question.
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter