Link to home
Start Free TrialLog in
Avatar of YellowbusTeam
YellowbusTeam

asked on

How can I set a GUID column to ROWGUID using T-SQL?

I have a source table with a primary key column that is a guid and is set as rowguid when the table was created.  I want to duplicate this table using a select-into command and then perform some actions on it and then drop the original table and rename this clone to the name of the original and continue.  I can use T-SQL to add the indexes and defaults back to the table but I can't figure out the syntax to set the column back to ROWGUID.  Does anyone know how to do it?
ASKER CERTIFIED SOLUTION
Avatar of Chrisedebo
Chrisedebo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YellowbusTeam
YellowbusTeam

ASKER

That's perfect, thanks Chrisedebo :)
Avatar of chapmandew
like this:

ALTER TABLE TableName ALTER COLUMN guidfield
      ADD ROWGUIDCOL
If you need to know the syntax for something you know how to do in sql management studio, make the change you want to then click on the generate change script button (looks like a little disk with a script behind it) on the tool bar and it will generate something similar to the script above.......not that I'm going to admit I'm a dirty cheat ;o)
I'm the same way.  :)  I added the rowguid in management studio and watched profiler to see what the interface did.
Aha - good tip -  I knew about that for creating things but didn't know you could find change syntax with it :)