There are times when I feel like writing that I am a day older in SQL Server. In fact, there are many who are looking for a solution that is simple enough. Have you ever searched online for something very simple. I often do and enjoy doing things which are straight forward and easy to change.
In this blog post, we will see how to change the datatypes of the column.
We will create a sample table and change the column datatypes.
USE tempdb GO 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 sp_help 'SampleTable' 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.
Let me know what you think of this blog post and please share your thoughts in the comment section of the blog post.
Reference: Pinal Dave (https://blog.sqlauthority.com)
29 Comments. Leave new
Hi Pinal
I want to change column from datetime datatype to date datatype , If I changed how it will impact on existing records??
hi we want to change our schema data type kindly help us