使用 SMO 编写脚本时可以更改脚本编写的 DATA 格式吗?
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获得所需结果的一种迂回方法是使用 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.