Solved

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

Posted on 2008-06-24
6
1,129 Views
Last Modified: 2010-04-21
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?
0
Comment
Question by:YellowbusTeam
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
Chrisedebo earned 500 total points
Comment Utility
This should do what you're after :o)
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/

BEGIN TRANSACTION

SET QUOTED_IDENTIFIER ON

SET ARITHABORT ON

SET NUMERIC_ROUNDABORT OFF

SET CONCAT_NULL_YIELDS_NULL ON

SET ANSI_NULLS ON

SET ANSI_PADDING ON

SET ANSI_WARNINGS ON

COMMIT

BEGIN TRANSACTION

GO

ALTER TABLE dbo.tablename ALTER COLUMN columnname

	ADD ROWGUIDCOL

GO

COMMIT

Open in new window

0
 

Author Closing Comment

by:YellowbusTeam
Comment Utility
That's perfect, thanks Chrisedebo :)
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
like this:

ALTER TABLE TableName ALTER COLUMN guidfield
      ADD ROWGUIDCOL
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 7

Expert Comment

by:Chrisedebo
Comment Utility
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)
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
I'm the same way.  :)  I added the rowguid in management studio and watched profiler to see what the interface did.
0
 

Author Comment

by:YellowbusTeam
Comment Utility
Aha - good tip -  I knew about that for creating things but didn't know you could find change syntax with it :)
0

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

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

771 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

10 Experts available now in Live!

Get 1:1 Help Now