I want to change the datatype of a column in a table in sql server. I used the following statement:
ALTER TABLE dbo.tbltest
ALTER COLUMN ID uniqueidentifie
You cannot convert from an integer to a uniqueidentifier
. But you can do it like this.
First delete old data from the table.
Alter the column to some text-format (such as VARCHAR(200)
).
ALTER TABLE dbo.tbltest
ALTER COLUMN ID VARCHAR(200)
ALTER TABLE dbo.tbltest
ALTER COLUMN ID uniqueidentifier
To be clear, you can't convert a column from numeric to uniqueidentifier
directly, but you can convert numeric
to varchar
to uniqueidentifier
.