5

I have been assisgned with a starnge assigment where i need to convert 40 tables columns from datetime2 to datetime.

this is the datetime format what i am having in my database.2007-11-12 00:00:00

it contains more than 90,000 records

Please assist

4

2 回答 2

7
  • 您必须检查您的值是否小于 1753 年 1 月 1 日(因为它们与 不兼容datetime)。例如

SELECT * FROM MyTable WHERE MyColumn < '1753-01-01'

  • 例如,您必须决定如何处理这些值(这里我将所有 < 1753-01-01 的值更改为 1753-01-01):

UPDATE MyTable SET MyColumn = '1753-01-01' WHERE MyColumn < '1753-01-01'

  • 修改列的类型

ALTER TABLE MyTable ALTER COLUMN MyColumn DATETIME

于 2013-08-02T11:54:33.550 回答
3

那只是 rediculos,datetime2 更准确,它具有更大的日期范围并占用相同的字节数(8)。

这是 mssql 的代码:

alter table tablename alter column colname datetime
于 2013-08-02T11:43:51.923 回答