Sunday, October 17, 2010

SQL SERVER – Change Column DataTypes

CREATE TABLE dbo.SampleTable
(ID INT, FirstCol VARCHAR(10), SecondCol DATETIME)
GO
ALTER TABLE dbo.SampleTable
ALTER COLUMN ID VARCHAR(100)
GO
ALTER TABLE dbo.SampleTable
ALTER COLUMN FirstCol VARCHAR(100)
GO
ALTER TABLE dbo.SampleTable
ALTER COLUMN SecondCol VARCHAR(100)
GO


In our example, it was possible to change the data types easily. If you face any errors, as per your error, you will have to adjust your business logic.
When running the last SP, you will note that you have successfully converted all the datatypes to another datatype

Rakesh walia

No comments:

Post a Comment