Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 800 tables. Most of the tables have a same column name 'LastModifiedByUserID'. Now, I want to change the datatype of that column in all the tables of my database. Is it possible with a stored procedure or any query rather than writing alter statement in every table.
Thanks in advance.
Posted

1 solution

Hi
Try This...
Before Do this Operation take your Data Base Backup :-)
SQL
SELECT 'ALTER TABLE '+OBJECT_NAME(C.ID) + ' ALTER COLUMN '+C.Name +' New_DataType'
FROM syscolumns C
INNER JOIN sys.tables T ON T.object_id=C.ID 
WHERE C.NAME = 'LastModifiedByUserID'
-- Note : Data Type is TIMESTAMP, You can't able to change the Data Type Using Script.

Regards,
GVPrabu
 
Share this answer
 
v3
Comments
Maciej Los 21-Mar-13 15:08pm    
Wow!
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900