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

╄→尐↘猪︶ㄣ 提交于 2020-08-04 19:55:10

问题:

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将excel文件转储到相关表中来添加该数据。

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. 每隔一段时间,我们要“刷新”相关表,这意味着将它们全部删除,重新创建它们并运行保存的MS Access附加查询。

The first part (dropping & re-creating) is an easy sql script, but the last part makes me cringe. 第一部分(删除和重新创建)是一个简单的sql脚本,但最后一部分让我感到有些畏缩。 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? 从该数据集自动生成大量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. 我能想到的唯一方法是将表保存到excel工作表,然后编写excel公式为每一行创建一个INSERT,这肯定不是最好的方法。

I'm using the 2008 Management Studio to connect to a SQL Server 2005 database. 我正在使用2008 Management Studio连接到SQL Server 2005数据库。


解决方案:

参考一: https://stackoom.com/question/47bs/为SQL-Server表自动生成INSERT语句的最佳方法是什么
参考二: https://oldbug.net/q/47bs/What-is-the-best-way-to-auto-generate-INSERT-statements-for-a-SQL-Server-table
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!