我使用的是 SQL Server 2012 Express。数据库有一个表 [config],其成员类型为“datetime”。通过 Management Studio 将其导出(仅数据)作为 SQL 脚本生成:
INSERT [dbo].[config] ([id], [name], [creation_date], ... ) VALUES (13, N'Test', CAST(N'2014-11-17 09:29: 07.047' AS 日期时间), ...)
现在,当执行生成的脚本时,它会提示日期时间类型的值无效。我可以通过用“T”替换日期和时间之间的空白来手动修复它:
INSERT [dbo].[config] ([id], [name], [creation_date], ... ) VALUES (13, N'Test', CAST(N'2014-11-17T 09:29:07.047' AS 日期时间), ...)
查看日期时间的文档,似乎不支持使用空白的格式。
如何生成具有受支持的日期时间格式(即包括“T”)的脚本?
如何在不更改导入脚本的情况下导入使用空白的格式?
顺便说一句,看起来它可以在其他 SQL Server 安装上运行,但我找不到区别。卸载并重新安装 SQL Server 也没有帮助。
最佳答案
How can I import the format that uses a blank without changing the imported script?
您必须更改导入脚本,但只需更改一点点即可。指定dateformat作为脚本开头的 ymd
。
set dateformat ymd;
How can I generate scripts with supported datetime format (i.e. incl. the 'T')?
投票支持改变...
"Generate scripts" for data, scripts datetime in a locale dependent format
关于sql-server - MS SQL Server 2012 将日期时间导出为无法导入的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971328/