使用从表中收集的值创建 SQL INSERT 脚本 [英] Create SQL INSERT Script with values gathered from table

查看:26
本文介绍了使用从表中收集的值创建 SQL INSERT 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个 INSERT 脚本,以便在另一个数据库中插入相同的数据.
如果在 SQL Server 中我选择脚本表为 > INSERT To",我可以轻松地重新创建 INSERT 语句的框架.但是,由于我有几条记录要迁移,因此我宁愿避免手动插入值.

I need to create a INSERT script in order to insert in another database the same data.
If in SQL Server I select "Script table as > INSERT To" I can easily recreate the skeleton for the INSERT statement. However since I have several records to migrate, I would prefer to avoid having to insert the values manually.

因此,有没有办法自动"获取 INSERT 脚本并填充值(来自目标表)?

我知道这可以通过 SSIS 完成,但我想知道是否也可以使用更快的解决方案.

I know this could be done with SSIS, but I am wondering whether it would be possible as well with a quicker solution.

推荐答案

您可以使用 SSMS 做到这一点.

You can do this with SSMS.

1 - 在对象资源管理器中右键单击您的数据库.
2 - 选择任务/生成脚本...
3 - 在 Set Scripting Options 页面上,单击 Advanced 按钮并确保 Types of data to script 设置为 Data only.

1 - Right-click your database in Object Explorer.
2 - Select Tasks/Generate Scripts...
3 - On the Set Scripting Options page, click the Advanced button and make sure Types of data to script is set to Data only.

生成的脚本将在顶部有一个 USE DATABASE 语句.将其更改为您想要插入数据的数据库.

The resulting script will have a USE DATABASE statement at the top. Change this to the database you would like to insert the data into.

这篇关于使用从表中收集的值创建 SQL INSERT 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆