none
How to generate GUID in SQL Server

    Question

  • Hello,

     

    I want to create unik primary key for my database.

    Somebody advice me to use the GUID.

    I'm not sure on how it can be created. I have to create it on my application side or database side?

     

    Kindly advice.

     

    Best regards,
      Tee Song Yann

    Thursday, April 19, 2007 8:50 AM

Answers

  • Hope this given example will help you.

    CREATE TABLE MyUniqueTable

    (UniqueColumn UNIQUEIDENTIFIER DEFAULT NEWID(),

    Characters VARCHAR(10) )

     

    INSERT INTO MyUniqueTable(Characters) VALUES ('abc')

     

    INSERT INTO MyUniqueTable VALUES (NEWID(), 'def')

     

    select * from MyUniqueTable

    Thursday, April 19, 2007 10:06 AM

All replies