Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to convert UniqueIdentifier to Primary key integer in

Sql server 2008
Posted
Comments
bbirajdar 13-Aug-12 6:06am    
Why do you need it ?

 
Share this answer
 
UniqueIdentifier is a Guid and cannot be convertet to an int. But if you add a new column INT and set it as primary key and is identity the database will give all rows a new id (int) And you can keep you UniqueIdentifier column or just delete it.. (unless it has a lot of relations...)
 
Share this answer
 
Uniqueidentifier is used to generate a surrogate key[^] and it contains both characters and numbers so it cannot be converted to any number data type.

If you want to convert it to something, you can use character datatypes, for example nvarchar. However, you normally shouldn't need to convert it to anything special since the only purpose of unique identifier is to identify a single record.

If you're looking for the .Net equivalent data type for parameters, you can use SqlDbType.UniqueIdentifier. See: SqlDbType Enumeration[^]

In my opinion keeping the primary key as an uniqueidentifier is an excellent choice, especially if replication is involved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900