是否可以将数据脚本编写为 SSIS 包中的 Insert 语句?

发布于 2024-09-01 07:41:06 字数 512 浏览 1 评论 0原文

SQL Server 2008 提供了使用 Management Studio 中的“生成脚本”选项将数据编写为 Insert 语句的功能。是否可以从 SSIS 包中访问相同的功能?

这就是我想要完成的任务:

我有一个计划作业,每晚运行并编写 SQL Server 2008 数据库中的所有架构和数据的脚本。然后,它使用该脚本创建镜像副本 SQLCE 3.5 数据库。我一直在使用 Narayana Vyas Kondreddi 的 sp_generate_inserts 存储过程来完成此任务,但它在处理少数数据类型时存在问题,并且在处理超过 4,000 个列时也存在问题(SQL Server 2000 天的遗留问题)。

脚本数据功能看起来可以解决我的问题,只要我能够将其自动化即可。

有什么建议吗?

SQL Server 2008 provides the ability to script data as Insert statements using the Generate Scripts option in Management Studio. Is it possible to access the same functionality from within a SSIS package?

Here's what I'm trying to accomplish:

I have a scheduled job that runs nightly and scripts out all the schema and data from an SQL Server 2008 database. It then uses the script to create a mirror copy SQLCE 3.5 database. I've been using Narayana Vyas Kondreddi's sp_generate_inserts stored procedure to accomplish this, but it has problems with few data types and also has issues with handling more than 4,000 columns (holdovers from SQL Server 2000 days).

The Script Data function looks like it could solve my problems, if only I could automate it.

Any suggestions?

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

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

发布评论

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

评论(2

伴我心暖 2024-09-08 07:41:06

通过使用 SMO 的 Scripter.EnumScript 方法,可以将所有表数据的脚本自动编写为 Insert 语句。这是我想出的代码。

Using conn As New SqlConnection(SqlServerConnectionString)
    Dim smoConn As New ServerConnection(conn)
    Dim smoServer As New Server(smoConn)
    Dim smoDatabase As Database = smoServer.Databases(smoConn.DatabaseName)
    Dim smoTables As SqlSmoObject() = New SqlSmoObject(2) {smoDatabase.Tables("Employee"), _
                                                           smoDatabase.Tables("Company"), _
                                                           smoDatabase.Tables("Job")}

    Dim smoScripter As New Scripter(smoServer)
    With smoScripter.Options
        .ScriptData = True
        .ScriptSchema = False
        .IncludeDatabaseContext = False
        .EnforceScriptingOptions = True
        .SchemaQualify = False
    End With

    Dim outputScript As New StringBuilder()
    For Each script As String In smoScripter.EnumScript(smoTables)
        outputScript.Append(script)
    Next

    Return outputScript.ToString()
End Using

来帮助我有点太晚了,我还发现其他一些人在 MSDN 论坛上讨论了相同的挑战:

ScriptData 不编写数据脚本

It is possible to automate the scripting of all a table's data as Insert statements by using SMO's Scripter.EnumScript method. Here is the code that I came up with.

Using conn As New SqlConnection(SqlServerConnectionString)
    Dim smoConn As New ServerConnection(conn)
    Dim smoServer As New Server(smoConn)
    Dim smoDatabase As Database = smoServer.Databases(smoConn.DatabaseName)
    Dim smoTables As SqlSmoObject() = New SqlSmoObject(2) {smoDatabase.Tables("Employee"), _
                                                           smoDatabase.Tables("Company"), _
                                                           smoDatabase.Tables("Job")}

    Dim smoScripter As New Scripter(smoServer)
    With smoScripter.Options
        .ScriptData = True
        .ScriptSchema = False
        .IncludeDatabaseContext = False
        .EnforceScriptingOptions = True
        .SchemaQualify = False
    End With

    Dim outputScript As New StringBuilder()
    For Each script As String In smoScripter.EnumScript(smoTables)
        outputScript.Append(script)
    Next

    Return outputScript.ToString()
End Using

A little too late to help me, I also found some other people who discussed the same challenge at the MSDN forums:

ScriptData doesn't script data

青春有你 2024-09-08 07:41:06

使用我的 Export2SqlCE 命令行实用程序,该实用程序以 SQL Compact 兼容方式编写数据和架构脚本脚本。 SMO 不支持 SQL Compact 语法和数据类型转换。

Use my Export2SqlCE command line utility, which scripts both data and schema in SQL Compact compatible script. SMO does not support SQL Compact syntax and data type conversion.

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