介绍 (Introduction)

This article is for people who need to replicate the SQL Server Databases. SQL Server includes several types of replications to synchronize the databases across different SQL Servers.

本文适用于需要复制SQL Server数据库的人员。 SQL Server包括几种复制类型,以跨不同SQL Server同步数据库。

Sometimes we need to replicate the data to have a Backup. Sometimes we need to synchronize Servers that are located in different cities or countries.

有时我们需要复制数据以具有备份。 有时我们需要同步位于不同城市或国家/地区的服务器。

In this article, we will introduce you to the SQL Server Replication Theory and then we will show a step-by-step tutorial to replicate a Table using the Merge replication.

在本文中,我们将向您介绍SQL Server复制理论,然后将显示分步教程,以使用合并复制来复制表。

复制类型 (Types of Replications)

In SQL Server, the main types of replication are SQL:

在SQL Server中,主要的复制类型是SQL:

  • Snapshot快照
  • Merge合并
  • Transactional交易性

You also have the Heterogeneous Replication with Oracle, which is out of the scope of this article.

您还可以使用Oracle进行异构复制 ,这不在本文的讨论范围之内。

复制中的角色 (Roles in replication)

There are three roles in a replication:

复制中有三个角色:

  • The Publisher is the SQL Server, which publishes the information to replicate (usually tables).发布服务器是SQL Server,它发布要复制的信息(通常是表)。
  • The Distributor is the SQL Server that distributes de information in each Subscriber. The distributor can be installed at the Publisher, in the Subscriber or in a separate SQL Server.分发服务器是在每个订阅服务器中分发信息SQL Server。 分发服务器可以安装在发布服务器,订阅服务器或单独SQL Server中。
  • The Subscriber is the SQL Server that receives the information Published.订阅服务器是接收发布信息SQL Server。

快照复制 (Snapshot Replication)

The snapshots replicates the complete table or tables selected in the Snapshot replication process. When the snapshot replication is applied, the entire snapshot is replicated.

快照复制在快照复制过程中选择的完整表或多个表。 应用快照复制时,将复制整个快照。

事务复制 (Transactional Replication)

In the transactional method, one of the SQL Servers is the publisher, which publishes the tables or objects to replicate, and the other is the subscriber (or the subscribers if multiple SQL Servers are being replicated).

在事务方法中,一个SQL Server是发布者,它发布要复制的表或对象,另一个是订阅者(如果要复制多个SQL Server,则是订阅者)。

合并复制 (Merge Replication)

For the first time, a snapshot is used to replicate the information and after that, all the data and schema is replicated every time is changed using triggers.

第一次使用快照复制信息,此后,每次使用触发器进行更改时,都会复制所有数据和架构。

先决条件 (Prerequisites)

  1. Two SQL Server or at least two SQL Server instances.两个SQL Server或至少两个SQL Server实例。
  2. Make sure that the SQL Server Agent Account is running under a common account for both Servers.确保SQL Server代理帐户在两个服务器的公共帐户下运行。
  3. A table to be replicated.要复制的表。

入门 (Getting started)

  1. In the SQL Server Management Studio (SSMS), open the node of the SQL Server with the table to be published. In this example, we are going to publish a table named emails installed in the DB1 database.

    在SQL Server Management Studio(SSMS)中,使用要发布的表打开SQL Server的节点。 在这个例子中,我们将发布一个安装在DB1数据库中的名为emails的表。

    Figure 1

    图1

  2. In the Replication Node right click on the Local Publication and select New Publication.

    在复制节点中,右键单击本地发布,然后选择新建发布。

    Figure 2

    图2

  3. In the new publication Window, press Next.

    在新的发布窗口中,按下一步。

    Figure 3

    图3

  4. Select the Server that will be used as a distributor. In this example, the Publisher and the Distributor will be the same Server,

    选择将用作分发服务器的服务器。 在此示例中,发布者和分发者将是同一台服务器,

    Figure 4

    图4

  5. You can optionally configure if you want the Agent to start automatically. This is recommended if you constantly require synchronization between SQL Servers.

    您可以选择配置是否希望代理自动启动。 如果您经常需要在SQL Server之间进行同步,则建议这样做。

    Figure 5

    图5

  6. All the replication types require a Snapshot. The Snapshot Folder allows you to specify the Path where the folder will be published.

    所有复制类型都需要一个快照。 Snapshot Folder(快照文件夹)允许您指定文件夹的发布路径。

    Figure 6

    图6

  7. Select the Database where you have the information to be published.

    选择您要发布信息的数据库。

    Figure 7

    图7

  8. Select the Replication type

    选择复制类型

    Figure 8

    图8

  9. Specify the SQL Server version of the Subscriber.

    指定订阅服务器SQL Server版本。

    Figure 8a

    图8a

  10. Select the tables or tables to Replicate.

    选择要复制的一个或多个表。

    Figure 9

    图9

  11. You can optionally add filters to Rows or Columns. This is common when you have some internal information that you do not want to replicate. Press Add if you want to add filters.

    您可以选择将过滤器添加到行或列。 当您有一些不想复制的内部信息时,这很常见。 如果要添加过滤器,请按添加。

    Figure 10

    图10

  12. In the Filter statement you can configure the T-SQL Sentences to filter the columns or to restrict the rows usually with a where clause.

    在Filter语句中,您可以配置T-SQL语句以通常使用where子句来过滤列或限制行。

    Figure 11

    图11

  13. You can create the snapshot immediately or Schedule at a specific time.

    您可以立即创建快照,也可以在特定时间计划。

    Figure 12

    图12

  14. With the Security Settings button, you will specify the account under which the connection will run.

    使用“安全设置”按钮,您将指定用于运行连接的帐户。

    Figure 13

    图13

  15. You can run under a specific account, impersonate the process Account, use a SQL Server Login.

    您可以在特定帐户下运行,模拟进程帐户,使用SQL Server登录名。

    Figure 14

    图14

  16. Once selected the security settings press Next.

    选择安全设置后,按下一步。

    Figure 15

    图15

  17. Select a publication type. In this example, Merge Replication.

    选择一种出版物类型。 在此示例中,合并复制。

  18. Select the version of the SQL Server Subscriber.

    选择SQL Server订阅服务器的版本。

  19. Create the publication and press Next.

    创建出版物,然后按下一步。

    Figure 16

    图16

  20. Specify a name for the Publication and press Finish.

    指定发布的名称,然后按完成。

    Figure 17

    图17

  21. If you open the SQL Server, you will be able to see a publication named db1: pub1.

    如果打开SQL Server,将可以看到名为db1的发布:pub1。

    Figure 18

    图18

  22. In the other server used as a Subscribers, go to Replication>Local Subscription and select New Subscriptions.

    在用作订阅服务器的另一台服务器中,转到“复制”>“本地订阅”,然后选择“新订阅”。

    Figure 19

    图19

  23. In the New Subscription Wizard, press Next.

    在“新建订阅向导”中,按“下一步”。

    Figure 20

    图20

  24. Select the Publisher Server where you published the article.

    选择您在其中发布文章的发布服务器。

    Figure 21

    图21

  25. You can select where you want the Merge Agent to run. It can run at the Distributor or at each subscriber.

    您可以选择希望合并代理运行的位置。 它可以在分发服务器或每个订阅服务器上运行。

    Figure 22

    图22

  26. At the subscriber database, you can create a new database to be used as the database subscriber to receive the data replicated.

    在订户数据库上,您可以创建一个新数据库,用作数据库订户以接收复制的数据。

    Figure 23

    图23

  27. Create a Database with the same name that the database used as the publisher.

    创建与该数据库用作发布者的名称相同的数据库。

    Figure 24

    图24

  28. You can choose the subscribers and the subscription database. Press Next.

    您可以选择订阅者和订阅数据库。 按下一步。

    Figure 25

    图25

  29. Click in the ellipsis button to specify the security accounts.

    单击省略号按钮以指定安全帐户。

    Figure 26

    图26

  30. You can specify the Schedule for the Synchronization.

    您可以指定同步时间表。

    Figure 27

    图27

  31. You have to Schedule when you want to initialize the replication with the snapshot publication.

    要使用快照发布初始化复制时,必须计划。

    Figure 28

    图28

  32. You also need to specify the type of subscription

    您还需要指定订阅类型

    Figure 29

    图29

  33. Finally, create the subscription.

    最后,创建订阅。

    Figure 30

    图30

  34. If everything is OK, add a new row to the table replicated at the publisher.

    如果一切正常,请将新行添加到在发布服务器上复制的表中。

    Figure 31

    图31

  35. At the publisher, go to Replication>Local Publication and select the article. Right click and select View Synchronization Status.

    在发布者处,转到“复制”>“本地发布”,然后选择文章。 右键单击并选择查看同步状态。

    Figure 32

    图32

  36. If you want to merge inmediately, press the start button. You will check that 1 insert is detected

    如果要立即合并,请按开始按钮。 您将检查是否检测到1个插入物

    Figure 33

    图33

  37. If everything is OK, you will be able to check the replication at the subscriber. Your replication is now ready!

    如果一切正常,您将能够在订阅服务器上检查复制。 复制已准备就绪!

    Figure 34

    图34

结论 (Conclusion)

As you can see, replicating a database is a straightforward process. You can replicate any database that you want anytime. In this article, we teach the basis of the replication, the replication types, roles and finally, we show how to create a Merge Replication.

如您所见,复制数据库是一个简单的过程。 您可以随时复制所需的任何数据库。 在本文中,我们将介绍复制的基础,复制类型,角色,最后,我们将展示如何创建合并复制。

翻译自: https://www.sqlshack.com/sql-server-replications/

SQL Server复制相关推荐

  1. 通往SQL Server复制的阶梯:一级- SQL服务器复制介绍

    链接:http://www.sqlservercentral.com/articles/Stairway+Series/72274/ 文章:Stairway to SQL Server Replica ...

  2. SQL Server 复制需要有实际的服务器名称才能连接到服务器

    条件:以云端服务器作为主服务器进行合并复制,在连接到服务器时提示"SQL Server 复制需要有实际的服务器名称才能连接到服务器",网上百度后说要新建别名.以为是在云端服务器上新 ...

  3. SQL Server复制需要有实际的服务器名称才能连接到服务器

    SQL Server 2005/2008 配置 Transactional  Replication 过程中,出现如下异常信息. 异常信息: Replication.Utilities ------- ...

  4. [解决方案]sql server复制需要有实际的服务器名称才能连接到服务器

    在配置数据同步的时候,要求相互同步的两台机器的数据库必须通过默认实例名称进行连接.如果你的默认实例已经删掉了,在当前实例上进行新建发布操作时候,会提示你:"由于未在SqlServer的此实例 ...

  5. SQL Server复制需要有实际的服务器名称才能连接到服务器 错误解决方案

    SQL Server 2005/2008 配置 Transactional  Replication 过程中,出现如下异常信息. 异常信息: Replication.Utilities ------- ...

  6. sql server 快照_添加新文章,删除文章,更改快照文件夹路径和SQL Server复制中的数据筛选器行

    sql server 快照 In the last articles, we have learned Configuring Snapshot and Transactional SQL Serve ...

  7. 镜像数据库上SQL Server复制

    This article will review on how to configure SQL Server Replication along with mirroring on a databa ...

  8. sql server合并行_合并SQL Server复制参数化的行筛选器问题

    sql server合并行 In this article we will discuss about SQL Server Merge Replication Parameterized row f ...

  9. sql server复制表_具有超过246列的表SQL Server复制

    sql server复制表 问题 (Problem) In our environment we use SQL Server merge replication to replicate data ...

  10. sql server 复制_SQL Server复制(合并)–复制什么,什么不复制

    sql server 复制 This article will show how triggers, indexes, constraints and foreign keys will replic ...

最新文章

  1. 去水印--《On the Effectiveness of Visible Watermarks》
  2. 用 Jackson 来处理 JSON
  3. ASP.NET 实现站内信功能(点对点发送,管理员群发)
  4. SIFT(ASIFT) Matching with RANSAC
  5. cass展点不在原位置,cass中打开一副图后,通过绘图处理-——展高程点,怎么之前的图形就不显示了,,只剩下高程点!!...
  6. Asp.Net 构架(HttpModule 介绍) - Part.3
  7. 【转】JVM内存管理:深入垃圾收集器与内存分配策略
  8. WINRAR 命令行语法[转载]
  9. Chrome浏览器提示您的连接不是私密连接解决办法
  10. Oracle数据库文件中的导入\导出(imp/exp命令)
  11. 翻新电子元器件识别的一些方法技巧
  12. win10与win7系统之间文件共享
  13. python爬虫得到谷歌学术搜索结果
  14. 高端时尚简历PPT模板-优页文档
  15. 从图形界面到会话界面
  16. edge等浏览器打开开发者工具(F12)之后在NetWork看不到请求头等信息
  17. 《MySQL》入门基础知识点大全:数据库操作、增删改查、联表查询、常用函数、MD5加密、事务特性、隔离级别
  18. libreCAD源码阅读笔记4
  19. 记录一下接多盟SDK遇到的问题
  20. 谷歌应用商店现木马程序、百万WiFi路由器面临漏洞风险|12月6日全球网络安全热点

热门文章

  1. 剑指offer.数值的整数次方
  2. 【BZOJ5249】【九省联考2018】—IIIDX(线段树)
  3. 【Nodejs】npm cnpm 淘宝镜像
  4. PHP生成随机数;订单号唯一
  5. 【C#】使用DWM实现无边框窗体阴影或全透窗体
  6. 61组第二次团队作业
  7. CSU 1803 2016(数论)
  8. Ubuntu 14.04开启ssh服务
  9. UVa 1605 (构造) Building for UN
  10. 算不算被虚度的这几年