Alter existing UNIQUEIDENTIFIER column to make it the ROWGUID

Posted on 2005-04-06
Last Modified: 2011-04-15
How do I, from within a proc, alter an exisiting table to make the PK column also the ROWGUID column?
I cannot see any way of doing it without dropping the column and recreatiing it with this constraint.

It must be possible to turn a column intoa ROWGUID column without dropping and remaking the column, because Enterprise Manager is able to do so with the IsRowGuid flag.

Question by:jasww
    LVL 17

    Accepted Solution

    try following this :

    create table MyTable (a uniqueidentifier, b integer
    constraint PK_MyTable primary key clustered (a)
    alter table dbo.MyTable alter column a add ROWGUIDCOL
    alter table dbo.MyTable add constraint DF_MyTable_a default (newid()) for a

    Author Comment

    Rock and roll.


    God don't you love T-SQl and it's oh-so-easy syntax?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    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…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    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.

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now