Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

How to change an increment field in a database table from Int to UniqueIdentifier

Posted on 2015-02-12
Last Modified: 2015-02-19
I have a table in a database with a data_type of INT that ties into other tables.  I need to change the datatype from INT to UniqueIdentifier for a third party product that requires the use of UniqueIdentifier for creating, editing, and deleting records from a SharePoint list.

How can I make this change to the table without effecting the records that already exist and tie to records in other tables?
Question by:mounty95
  • 2
  • 2
  • 2
  • +1
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40606584
Consider adding a new unique key to this table for their use.
LVL 35

Expert Comment

by:David Todd
ID: 40608451

To expand on efhtebas post - I don't think that you can change that column. I think you will need to add another column with whatever constraints are appropriate, populate this column for your third party product, and as you don't want to affect other tables, leave the existing int identity as it is.

LVL 48

Expert Comment

by:Vitor Montalvão
ID: 40613734
David Todd is right. An uniqueidentifier column is 16byte GUID so you can't convert from INT.
Example of a value for a GUID: 0B984625-E58C-4DF1-9862-E1C87B27AA0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 40616370

So if I am understanding this correctly, I need to do the following:
1.  Create a new column in primary table with a GUID.
2.  Populate that column for all existing records.

And then do I have to create that same GUID column in all of the other tables and update them with the GUID from the primary table or do I just have two numbers being created with every new record and the GUID simply for the third party app and the int for the relation with other tables?

Thank you all for helping me with this.
LVL 48

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 total points
ID: 40616381
You need to use the NEWID() function to get a new GUID.
I'll drop the INT columns and update the related tables with the GUID column.
LVL 35

Accepted Solution

David Todd earned 250 total points
ID: 40617970

On one hand, its a perfect pain to change the ID column from int to GUID, and cascade that to other tables. So on one hand, this is the better solution, on the other it could be a lot of work.

I'd be inclined if time is in short supply to not propagate this change to other tables, and just keep the GUID as an alternate key.


Author Comment

ID: 40619077
So I am not sure how I was able to do this in my test environment, but I was able to add a column, give it a uniqueidentifier data type, used the newid() function in the default value or binding column property and was able to get the existing records to populate with a value, but now I can seem to do it with my live environment.  I am not sure what I did to get it to work, but now not work.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Managing Columnstore Indexes 2 38
SSRS 2013 - Creating a summarized report 19 47
Text file into sql server 5 32
too many installs coming along with SQL 2016? 1 14
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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