Gokul's Blog

Alter table for column Length

Leave a comment

IF EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[MyTable]') AND type in (N'U'))
	--Increase the size of the [Name] column.
	IF EXISTS (SELECT name, TYPE_NAME(system_type_id), max_length, precision, scale
	FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.MyTable') AND name = 'ColName'
	AND max_length = 200)
		PRINT '-- Increasing the size of the Name nvarchar column to 255.'
		ALTER TABLE MyDatabase.dbo.MyTable 
		ALTER COLUMN [ColName] nvarchar(255);

MSDN Article: http://msdn.microsoft.com/en-us/library/ms190273(v=SQL.90).aspx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s