如何为包含所有存储行的现有 SQL Server 表生成 INSERT 脚本?
我正在寻找一种使用 SQL Management Studio 2008 R2 生成“创建并插入所有行”脚本的方法。
我知道我可以创建一个“创建表”脚本。
我还可以创建一个“插入”脚本,但这只会生成带有占位符的单行。
有没有办法生成包含所有当前存储的行的插入脚本?
I'm looking for a way to generate a "Create and insert all rows" script with SQL Management Studio 2008 R2.
I know that I can create a "create table" script.
I can also create an "insert in" script, but that will only generate a single row with placeholders.
Is there a way to generate an insert script that contains all currently stored rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,但您需要在数据库级别运行它。
右键单击SSMS中的数据库,选择“任务”、“生成脚本...”。当您完成操作时,您将进入“脚本选项”部分。单击“高级”,在弹出的列表中显示“要编写脚本的数据类型”,您可以选择数据和/或架构。
Yes, but you'll need to run it at the database level.
Right-click the database in SSMS, select "Tasks", "Generate Scripts...". As you work through, you'll get to a "Scripting Options" section. Click on "Advanced", and in the list that pops up, where it says "Types of data to script", you've got the option to select Data and/or Schema.
该脚本生成现有数据的插入语句。这是一个存储过程,您需要运行一次,然后它就是为您量身定制的。
我尝试寻找这类东西一段时间,但对结果不满意,所以我编写了这个存储过程。
示例:
(1) 这里
dbo
是模式,test 是表名,1=1
是条件。(2) 这里
dbo
是模式,test是表名,name='neeraj'
是条件。这是存储过程
This script generates insert statements of your existing data. This is a stored procedure which you need to run once and then it is tailor made for you.
I tried to find this kind of stuff for a while but wasn't satisfied with the results, so I wrote this stored procedure.
Example:
(1) Here
dbo
is schema and test is tablename and1=1
is condition.(2) Here
dbo
is schema and test is tablename andname='neeraj'
is condition.Here is the stored procedure
是的,使用商业但便宜的 SSMS Tools Pack 插件,它有一个漂亮的“从结果集、表或生成插入语句”数据库”功能
Yes, use the commercial but inexpensive SSMS Tools Pack addin which has a nifty "Generate Insert statements from resultsets, tables or database" feature
只是为了分享,我开发了自己的脚本来做到这一点。请随意使用它。它生成“SELECT”语句,然后您可以在表上运行该语句以生成“INSERT”语句。
Just to share, I've developed my own script to do it. Feel free to use it. It generates "SELECT" statements that you can then run on the tables to generate the "INSERT" statements.