如何将表中的所有数据导出为可插入的 sql 格式?

2022-01-20 00:00:00 复制 sql export sql-server ssms

我在 Microsoft SQL Server Management Studio 的数据库(称为 A_db)中有一个表(称为 A_table),有 10 行.

I have a Table (call it A_table) in a database (call it A_db) in Microsoft SQL Server Management Studio, and there are 10 rows.

我有另一个数据库(叫它B_db),它有一个表(叫它B_table),它的列设置与A_table 有.但是 B_table 是空的.

I have another database (call it B_db), and it has a Table (call it B_table), which has the same column settings as A_table has. But the B_table is empty.

我想要什么:

  • 复制从 A_tableB_table 的每一行.
  • Copy every rows from A_table to B_table.

Microsoft SQL Server Management Studio 2012 中是否有任何选项可以从表中创建插入 SQL?或者还有其他选择吗?

Is there any option in Microsoft SQL Server Management Studio 2012, to create an insert SQL from a table? Or is there any other option to do that?

推荐答案

快捷方式:

  1. 右键数据库
  2. 指向 tasks 在 SSMS 2017 中,您需要忽略第 2 步 - 生成脚本选项位于上下文菜单的顶层 感谢 Daniel 更新评论.
  3. 选择生成脚本
  4. 点击下一步
  5. 选择表格
  6. 点击下一步
  7. 点击高级
  8. 滚动到 脚本的数据类型 - 在 SMSS 2014 中称为 脚本的数据类型 感谢 Ellesedil 用于评论
  9. 选择仅数据
  10. 点击确定"关闭高级脚本选项窗口
  11. 单击下一步并生成您的脚本
  1. Right click database
  2. Point to tasks In SSMS 2017 you need to ignore step 2 - the generate scripts options is at the top level of the context menu Thanks to Daniel for the comment to update.
  3. Select generate scripts
  4. Click next
  5. Choose tables
  6. Click next
  7. Click advanced
  8. Scroll to Types of data to script - Called types of data to script in SMSS 2014 Thanks to Ellesedil for commenting
  9. Select data only
  10. Click on 'Ok' to close the advanced script options window
  11. Click next and generate your script

我通常在这种情况下生成一个新的查询编辑器窗口,然后在需要的地方进行任何修改.

I usually in cases like this generate to a new query editor window and then just do any modifications where needed.

相关文章