Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify the column width by using T_SQL 2

Status
Not open for further replies.

wg26

Programmer
Mar 21, 2002
135
US
Hi Everyone:

Can anyone please tell me how I can modify the column (varchar) width from 255 to say 2000 by using T_SQL....what is the syntax? I know I can get it done through EM.But I need to know how to do it by using T_SQL...Thanks
 
Alter Table tablename
Alter column colname varchar(2000)

This is explained in SQL BOL under the topic "Alter Table." Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
How about if you wanted to use a variable, say find the max len of a column then use the variable for the new size of a column, when I try this I get incorrect syntax.

alter table temp
alter column abc char(@newSize)
 
You'll have to use dynamic SQL to accomplish this.

Declare @sql varchar(200)

Select @sql='alter table temp' +
' alter column abc char(' +
str(@newSize) + ')'

exec(@sql)
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top