Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 809 | Views in the last 30 days: 7
 
Related Articles
FORUM

Change company name in SQL Server 2005

Change company name in SQL Server 2005

SCRIPT

Change the collation of Columns

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

SCRIPT

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

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

FORUM

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

SSIS Script Task for Changing column values

FORUM

Working with multiple Database change Release.

Latest database change script release should check for previous database change too

Tags
char    
nchar    
nvarchar    
varchar    
varchar(max) and nvarchar(max)    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones