更改多列的数据类型 [英] change datatype for multiple columns
本文介绍了更改多列的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有800张桌子。大多数表都有相同的列名''LastModifiedByUserID''。现在,我想在我的数据库的所有表中更改该列的数据类型。是否可以使用存储过程或任何查询而不是在每个表中编写alter语句。
提前谢谢。
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.
推荐答案
嗨
试试这个...
在此操作之前进行数据库备份:-)
Hi
Try This...
Before Do this Operation take your Data Base Backup :-)
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.
问候,
GVPrabu
Regards,
GVPrabu
这篇关于更改多列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文