Total Pageviews

Change column data types


Below are the syntax to change the data type of a column in SQL Server table :-

ALTER TABLE <schema>.<table_name>
ALTER COLUMN <column> <new data type>


Example:-

Let's create a table and confirm it's schema:-



 

Now we change the data type of column "name" from "CHAR(100)" to "VARCHAR(10)" and confirm the schema of table:-



* If we have data in our column then other data related conditions should also get considered before changing the data type of a column.

No comments:

Post a Comment