sql-server - MS SQL Server 2012 将日期时间导出为无法导入的脚本

标签 sql-server datetime iso8601

我使用的是 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/

相关文章:

python - 日期时间到十进制以使用 Python 拉入 matplotlib

javascript - Node js 中的新日期(年、月、日)自动转换为 UTC 时区

javascript - 时区和 DateTimeField - Django

c# - C# 中的 SQL 查询错误 : Using SELECT JOIN WHERE OR

java - MyEclipse Professional 在与 MS sql 服务器连接时通过数据库浏览器给出 ssl 错误

sql-server - 使用 DBI 连接到 SQL Server

datetime - 将时间转换为上午/下午 flutter

Python - 将原始日期时间转换为 UTC

kettle - 在 Pentaho 数据集成中使用偏移量处理 ISO8601 时间戳

sql-server - 如何将存储在表中的路径与 OPENROWSET 一起使用?