简体   繁体   English

如何使用SQL Management Studio在数据库之间传输所有表?

[英]How do you transfer all tables between databases using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. 当我右键单击要从中导出数据的数据库时,只能选择一个表或视图,而不能导出所有数据。 Is there a way to export all of the data? 有没有办法导出所有数据?

If this is not possible, could you advise on how I could do the following: 如果这不可能,您能建议我如何执行以下操作:

  • I have two databases, with the same table names, but one has more data than the other 我有两个数据库,它们的表名相同,但是一个数据库比另一个数据库具有更多的数据
  • They both have different database names (Table names are identical) 它们都有不同的数据库名称(表名称相同)
  • They are both on different servers 它们都在不同的服务器上

I need to get all of the additional data from the larger database, into the smaller database. 我需要将所有其他数据从较大的数据库获取到较小的数据库。

Both are MS SQL databases 两者都是MS SQL数据库

Being that both are MS SQL Servers, on different hosts... why bother with CSV when you can setup a Linked Server instance so you can access one instance from the other via a SQL statement? 两者都是在不同主机上的MS SQL Server ...为什么在设置Linked Server实例以便可以通过SQL语句从另一个实例访问一个实例时又打扰CSV?

  1. Make sure you have a valid user on the instance you want to retrieve data from - it must have access to the table(s) 确保您要从中检索数据的实例上有一个有效用户-它必须有权访问表
  2. Create the Linked Server instance 创建链接服务器实例
  3. Reference the name in queries using four name syntax: 使用四种名称语法在查询中引用名称:

     INSERT INTO db1.dbo.SmallerTable SELECT * FROM linked_server.db.dbo.LargerTable lt WHERE NOT EXISTS(SELECT NULL FROM db1.dbo.SmallerTable st WHERE st.col = lt.col) 

Replace WHERE st.col = lt.col with whatever criteria you consider to be duplicate values between the two tables. WHERE st.col = lt.col替换为您认为是两个表之间重复值的任何条件。

There is also a very good tool by Redgate software that syncs data between two databases. Redgate软件还有一个非常好的工具,可以在两个数据库之间同步数据。

I've also used SQL scripter before to generate a SQL file with insert statements that you can run on the other database to insert the data. 之前,我还使用过SQL脚本编写器来生成带有插入语句的SQL文件,您可以在其他数据库上运行该语句来插入数据。

If you right-click on the database, under the Tasks menu, you can use the Generate Scripts option to produce SQL scripts for all the tables and data. 如果右键单击数据库,则在“任务”菜单下,可以使用“生成脚本”选项为所有表和数据生成SQL脚本。 See this blog post for details. 有关详细信息,请参见此博客文章 If you want to sync the second database with the first, then you're better off using something like Redgate as suggested in mpenrow's answer. 如果要与第二个数据库同步,那么最好使用mpenrow答案中建议的Redgate之类的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用SQL查询在数据库之间进行数据传输 - Data Transfer Between Databases Using SQL Queries 如何在SQL Server Management Studio中关闭与本地数据库的所有连接? - How do you close all connections to a local database in SQL Server Management Studio? 如何使用 SQL Server Management Studio 连接相关表中的数据? - How do I concatenate data from related tables using SQL Server Management Studio? 如何在SQL Server Management Studio中找出哪些数据库的哪些表中具有给定名称的列? - How can i find out which tables in which databases have a column with a given name in SQL Server Management Studio? 如何在SQL Server 2005数据库之间传输存储过程 - how to transfer stored procedures between SQL Server 2005 databases 如何在Oracle SQL中的两个表之间使用更新 - How do you use an update between two tables in Oracle SQL SQL Server Management Studio 2012 - 将数据库的所有表导出为 csv - SQL Server Management Studio 2012 - Export all tables of database as csv 从 Microsoft SQL 服务器管理工​​作室删除数据库中的所有表 - Drop all the tables in a DB from Microsoft SQL server management studio 在SQL数据之间传递到不同的数据库 - IN SQL DATA TRANSFER Between To different databases 如何在 SQL Server 中查找所有数据库中所有表的列名 - How to find column names for all tables in all databases in SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM