Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 91
  • Last Modified:

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

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?
0
mounty95
Asked:
mounty95
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Mike EghtebasDatabase and Application DeveloperCommented:
Consider adding a new unique key to this table for their use.
0
 
David ToddSenior DBACommented:
Hi,

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.

HTH
  David
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
mounty95Author Commented:
All,

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.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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.
0
 
David ToddSenior DBACommented:
Hi,

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.

Regards
  David
0
 
mounty95Author Commented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now