Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为“smalldatetime”数据类型的“LastModifiedDate”列。
该列几乎存在于我在数据库中的所有表中。
我想将此列更改为“日期时间”数据类型。
有没有办法用 sql 脚本做到这一点?
要生成一个脚本,你可以做
SELECT 'ALTER TABLE [' + Table_Schema + '].[' + Table_Name + '] ' + 'ALTER COLUMN [' + Column_Name + '] DATETIME;' FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'LastModifiedDate'