使用 SMO 编写脚本时可以更改脚本编写的 DATA 格式吗?

发布于 2024-08-16 05:32:19 字数 862 浏览 1 评论 0原文

我想使用 SMO 生成一组插入语句以在环境之间复制数据。我可以正常工作,但由于某种原因,日期时间字段被格式化为转换为日期时间的十六进制值。这使得脚本难以阅读并且无法更新。有没有办法让我更改它以使用日期的字符串表示形式?

用于生成的代码:

scripter = New Scripter(<server>)
scripter.Options.ScriptData = True
...
For Each s As String In scripter.EnumScript(list)
    writer.WriteLine(FormatScript(s))
Next

我想将其更改

INSERT [dbo].[dmMessages] ([MessageId], [MessageCd], [MessageDesc], [Status], [EnteredBy], [EnteredDt])
VALUES (1, N'GenericMessages.FieldRequired', N'The {0} field is required.', 1, N'System', CAST(0x00009B4900000000 AS DateTime))

为...

INSERT [dbo].[dmMessages] ([MessageId], [MessageCd], [MessageDesc], [Status], [EnteredBy], [EnteredDt])
VALUES (1, N'GenericMessages.FieldRequired', N'The {0} field is required.', 1, N'System', '2009-1-1 13:00:00:000')

I would like to use SMO to generate a set of insert statements to copy data between environments. I have this working, but for some reason, datetime fields are formated as hex values that are casted to datetime. This makes the scripts hard to read and impossible to update. Is there a way for me to change this to use a string representation of the date?

Code used to generate:

scripter = New Scripter(<server>)
scripter.Options.ScriptData = True
...
For Each s As String In scripter.EnumScript(list)
    writer.WriteLine(FormatScript(s))
Next

I would like to change this...

INSERT [dbo].[dmMessages] ([MessageId], [MessageCd], [MessageDesc], [Status], [EnteredBy], [EnteredDt])
VALUES (1, N'GenericMessages.FieldRequired', N'The {0} field is required.', 1, N'System', CAST(0x00009B4900000000 AS DateTime))

to

INSERT [dbo].[dmMessages] ([MessageId], [MessageCd], [MessageDesc], [Status], [EnteredBy], [EnteredDt])
VALUES (1, N'GenericMessages.FieldRequired', N'The {0} field is required.', 1, N'System', '2009-1-1 13:00:00:000')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2024-08-23 05:32:19

获得所需结果的一种迂回方法是使用 BCP 导出数据并使用批量插入导入数据,而不是让 SMO 编写数据脚本。请阅读此处 了解更多详情。

One round-about way to get the results you are looking for would be to use BCP to export data and bulk insert to import data as opposed to letting SMO script the data. Read here for more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文