Friday, March 19, 2021

How to increase length of existing VARCHAR column in SQL Server

You can increase the length of a VARCHAR column without losing existing data in SQL Server. All you need to do is execute the following ALTER TABLE statements. Though, you need to specify NULL or NOT NULL constraint explicitly, depending upon your data.

Here is the SQL command you can use to increase the length of a VARCHAR column in SQL Server:

ALTER TABLE Books ALTER COLUMN title VARCHAR (432)

This command increases the length of the title column of the Books table to 432 characters. You can use the same command to increase the length of CHAR, NCHAR, or NVARCHAR columns as well.