SQL Server 7.0

May 17, 2009 at 05:06:26
Specs: Windows XP
After having created a table and inserted values in it, is there any way to change the length of the datatypes in SQL Server?

See More: SQL Server 7.0

Report •

May 26, 2009 at 10:37:33
You can use the Alter Table command.


Alter Table <tablename>
Alter Column <columnname> <datatype>

If you had a table named Employee and column LastName that was originally varchar(20) and you wanted to make it varchar(22),use

Alter Table Employee
Alter Column LastName varchar(22)

If you want to make the column shorter and that would result in truncating data you will get an error. In that case, first run an update to truncate the data yourself.
Such as:

Update Employee
Set LastName = Substring(Lastname, 1, 15)

Alter Table Employee
Alter Column Employee varchar(15)

Report •

May 31, 2009 at 05:14:28
Thanks for your reply. It was a great answer and it worked.

Report •

Related Solutions

Ask Question