Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating alter table script
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01346196
Message ID:
01346214
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>With this select
>select Table_Name, Column_Name, Data_Type, Character_Maximum_Length from information_schema.columns where Character_Maximum_Length >=100 order by 1,2
>
>I can get a list of all potentially dangerous fields. Now I want to write a procedure to generate a script to change all of these fields to varchar(100) (not execute it, of course).
>
>How should I proceed in writting such code?
>
>Thanks in advance.
DECLARE @Test varchar(max)
SET @Test = NULL
select @Test = ISNULL(@Test,'')+'ALTER TABLE '+Table_Name+' ALTER COLUMN '+Column_Name+' '+Data_Type+'(100)'+CHAR(13)+CHAR(10) 
       from information_schema.columns where Character_Maximum_Length >=100 order by Table_Name,Column_Name
print @Test
NOT TESTED
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform