SQL Server 2008: Bulk Datatype Change

前端 未结 4 669
失恋的感觉
失恋的感觉 2021-01-20 11:32

I have an SQL Server 2008 database with many tables. I\'ve been using the now lame datetime datatype and want to use the new and better datetime2.

4条回答
  •  猫巷女王i
    2021-01-20 11:46

    I would use a query window, and output all of the ALTER TABLE statements you need to perform this. Once you have them all generated, you can run the result against the database.

    if you select from SYSCOLUMNS the names of the tables and fields that you want, you can generate the statements you need to change all of the columns in the database to datetime2.

    ALTER TABLE {tablename} ALTER COLUMN {fieldname} datetime2 [NULL | NOT NULL]
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题