SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Generate script to change column length of string datatypes in a DB

By Venugopal Saride,

Step 1: Run the script in Part 1 and identify the column data type and size of the column and the column property (NULL / NOT NULL)  and number of columns to be changed.

Step 2: Select the target database and run Part 2, which will generate the script required.

Step 3: Copy the script and execute on the target database and change the column size.

This script can be used for char,nchar,varchar,nvarchar to any size including MAX column length (Refer to Part 3)

One of the use case I can think of this script is changing company name. Due to recent acquisitions, we have to keep changing the company name. Ex:- Company column in the HR / Finance / Revenue / DW databases is declared as varchar(10) / char(8) as you know your company name, now that you have to update your company to the new company which has more charcters then 10 then this script will be handy :).

For me it used to update my jdbc URL column length as we want to add the failover string to the actual jdbc url through out our configuration tables.

email me incase you need more information: cusvenus@gmail.com

Total article views: 859 | Views in the last 30 days: 2
Related Articles

Change company name in SQL Server 2005

Change company name in SQL Server 2005


Change the collation of Columns

This script changes the collation of columns to default database collation in all the tables


Script to change auto growth settings for all databases in SQL Server

Script to change auto growth settings for all databases in SQL Server.


Script Task In SSIS to Check column with Same value and change it accordingly

SSIS Script Task for Changing column values


Generate add / alter script for missing / different type columns

This query generate add/alter script for missing or different columns. Execute on source database an...

varchar(max) and nvarchar(max)