• <i id='0uaHT'><tr id='0uaHT'><dt id='0uaHT'><q id='0uaHT'><span id='0uaHT'><b id='0uaHT'><form id='0uaHT'><ins id='0uaHT'></ins><ul id='0uaHT'></ul><sub id='0uaHT'></sub></form><legend id='0uaHT'></legend><bdo id='0uaHT'><pre id='0uaHT'><center id='0uaHT'></center></pre></bdo></b><th id='0uaHT'></th></span></q></dt></tr></i><div id='0uaHT'><tfoot id='0uaHT'></tfoot><dl id='0uaHT'><fieldset id='0uaHT'></fieldset></dl></div>

  • <small id='0uaHT'></small><noframes id='0uaHT'>

    <tfoot id='0uaHT'></tfoot>

  • <legend id='0uaHT'><style id='0uaHT'><dir id='0uaHT'><q id='0uaHT'></q></dir></style></legend>
    • <bdo id='0uaHT'></bdo><ul id='0uaHT'></ul>

        为 SQL Server 表自动生成 INSERT 语句的最佳方法是什么?

        时间:2023-07-17

            • <legend id='jZ0Ab'><style id='jZ0Ab'><dir id='jZ0Ab'><q id='jZ0Ab'></q></dir></style></legend>

              <small id='jZ0Ab'></small><noframes id='jZ0Ab'>

            • <i id='jZ0Ab'><tr id='jZ0Ab'><dt id='jZ0Ab'><q id='jZ0Ab'><span id='jZ0Ab'><b id='jZ0Ab'><form id='jZ0Ab'><ins id='jZ0Ab'></ins><ul id='jZ0Ab'></ul><sub id='jZ0Ab'></sub></form><legend id='jZ0Ab'></legend><bdo id='jZ0Ab'><pre id='jZ0Ab'><center id='jZ0Ab'></center></pre></bdo></b><th id='jZ0Ab'></th></span></q></dt></tr></i><div id='jZ0Ab'><tfoot id='jZ0Ab'></tfoot><dl id='jZ0Ab'><fieldset id='jZ0Ab'></fieldset></dl></div>
                <tbody id='jZ0Ab'></tbody>
                <bdo id='jZ0Ab'></bdo><ul id='jZ0Ab'></ul>

                • <tfoot id='jZ0Ab'></tfoot>
                • 本文介绍了为 SQL Server 表自动生成 INSERT 语句的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们正在编写一个新的应用程序,在测试时,我们将需要一堆虚拟数据.我已经通过使用 MS Access 将 excel 文件转储到相关表中来添加该数据.

                  We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables.

                  我们经常想要刷新"相关表,这意味着将它们全部删除,重新创建它们,并运行保存的 MS Access 追加查询.

                  Every so often, we want to "refresh" the relevant tables, which means dropping them all, re-creating them, and running a saved MS Access append query.

                  第一部分(删除和重新创建)是一个简单的 sql 脚本,但最后一部分让我感到畏缩.我想要一个包含一堆 INSERT 的设置脚本来重新生成虚拟数据.

                  The first part (dropping & re-creating) is an easy sql script, but the last part makes me cringe. I want a single setup script that has a bunch of INSERTs to regenerate the dummy data.

                  我现在有表格中的数据.从该数据集自动生成大量 INSERT 语句的最佳方法是什么?

                  I have the data in the tables now. What is the best way to automatically generate a big list of INSERT statements from that dataset?

                  我能想到的唯一方法是将表格保存到excel表中,然后编写一个excel公式为每一行创建一个INSERT,这肯定不是最好的方法.

                  The only way I can think of doing it is to save the table to an excel sheet and then write an excel formula to create an INSERT for every row, which is surely not the best way.

                  我使用 2008 Management Studio 连接到 SQL Server 2005 数据库.

                  I'm using the 2008 Management Studio to connect to a SQL Server 2005 database.

                  推荐答案

                  Microsoft 应该宣传 SSMS 2008 的此功能.您正在寻找的功能内置于 生成脚本 实用程序中,但功能默认情况下关闭,必须在编写表脚本时启用.

                  Microsoft should advertise this functionality of SSMS 2008. The feature you are looking for is built into the Generate Script utility, but the functionality is turned off by default and must be enabled when scripting a table.

                  这是为表中的所有数据生成 INSERT 语句的快速运行,不使用 SQL Management Studio 2008 的脚本或加载项:

                  This is a quick run through to generate the INSERT statements for all of the data in your table, using no scripts or add-ins to SQL Management Studio 2008:

                  1. 右键单击数据库并转到任务 > 生成脚本.
                  2. 选择要针对其生成脚本的表(或对象).
                  3. 转到设置脚本选项标签,然后点击高级按钮.
                  4. 常规类别中,转到要编写脚本的数据类型
                  5. 有 3 个选项:仅架构仅数据架构和数据.选择适当的选项并点击确定.
                  1. Right-click on the database and go to Tasks > Generate Scripts.
                  2. Select the tables (or objects) that you want to generate the script against.
                  3. Go to Set scripting options tab and click on the Advanced button.
                  4. In the General category, go to Type of data to script
                  5. There are 3 options: Schema Only, Data Only, and Schema and Data. Select the appropriate option and click on OK.

                  然后,您将直接从 SSMS 中获得 CREATE TABLE 语句和所有 INSERT 语句用于数据.

                  You will then get the CREATE TABLE statement and all of the INSERT statements for the data straight out of SSMS.

                  这篇关于为 SQL Server 表自动生成 INSERT 语句的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:客户端 PC 上的 LocalDB 部署 下一篇:SQL Server CTE 和递归示例

                  相关文章

                  <i id='JZySm'><tr id='JZySm'><dt id='JZySm'><q id='JZySm'><span id='JZySm'><b id='JZySm'><form id='JZySm'><ins id='JZySm'></ins><ul id='JZySm'></ul><sub id='JZySm'></sub></form><legend id='JZySm'></legend><bdo id='JZySm'><pre id='JZySm'><center id='JZySm'></center></pre></bdo></b><th id='JZySm'></th></span></q></dt></tr></i><div id='JZySm'><tfoot id='JZySm'></tfoot><dl id='JZySm'><fieldset id='JZySm'></fieldset></dl></div>

                    1. <small id='JZySm'></small><noframes id='JZySm'>

                        <bdo id='JZySm'></bdo><ul id='JZySm'></ul>
                      <legend id='JZySm'><style id='JZySm'><dir id='JZySm'><q id='JZySm'></q></dir></style></legend>
                    2. <tfoot id='JZySm'></tfoot>