How can I create GUID in store proecdure?

Posted on 2005-05-15
Last Modified: 2010-03-19
How can I create GUID in store proecdure? Example please.
Question by:musclejack
    LVL 28

    Accepted Solution

    DECLARE @GUID uniqueidentifier


    LVL 3

    Expert Comment

    Return Types

    A. Use the NEWID function with a variable
    This example uses NEWID to assign a value to a variable declared as the uniqueidentifier data type. The value of the uniqueidentifier data type variable is printed before the value is tested.

    -- Creating a local variable with DECLARE/SET syntax.

    DECLARE @myid uniqueidentifier

    SET @myid = NEWID()

    PRINT 'Value of @myid is: '+ CONVERT(varchar(255), @myid)


    Here is the result set:

    Value of @myid is: 6F9619FF-8B86-D011-B42D-00C04FC964FF



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now