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

sql server 快照

In the last articles, we have learned Configuring Snapshot and Transactional SQL Server replication and Configuring Peer to Peer and Merge SQL replication. Now, once we configured SQL Server replication, there will be some instances where we need to modify the SQL Server replication configuration as per the project updates. In this article, we will learn a few modifications in the existing SQL Replication such as Add new article, drop an article and change the Snapshot folder path and data filter in the current SQL Server replication.

在上一篇文章中,我们学习了配置快照和事务型SQL Server复制以及配置点对点和合并SQL复制 。 现在,一旦我们配置了SQL Server复制,就会有一些实例需要根据项目更新来修改SQL Server复制配置。 在本文中,我们将学习对现有SQL复制的一些修改,例如添加新文章,删除文章并更改当前SQL Server复制中的Snapshot文件夹路径和数据过滤器。

将新文章添加到现有已发布的数据库中 (Add new Articles into the existing published database)

In this section, we will learn, Add a new article into the existing published database. Once we created the publication, the publication contains few sets of database objects like tables, views and stored procedures. As per the project requirement sometimes we need to create new tables or views or stored procedures into the existing published database for some calculations or storing specific limited data. If we also wish to replicate those tables or views or stored procedures into the current SQL replication, then we need to add new database objects into the published database. This section will help to insert new articles into the existing published database of the SQL Server replication.

在本节中,我们将学习将新文章添加到现有已发布的数据库中。 创建发布后,发布包含几组数据库对象,例如表,视图和存储过程。 根据项目要求,有时我们需要在现有的已发布数据库中创建新表或视图或存储过程,以进行一些计算或存储特定的有限数据。 如果我们还希望将这些表或视图或存储过程复制到当前SQL复制中,则需要将新的数据库对象添加到已发布的数据库中。 本节将帮助将新文章插入到SQL Server复制的现有已发布数据库中。

I have already configured the transactional SQL replication on the node SQL1 for the database AdventuresWorksLT2012 as shown in the following fig.

我已经在数据库AdventuresWorksLT2012的节点SQL1上配置了事务SQL复制,如下图所示。

Published database of the replication

Before adding a new article, first, we need to check, which are the database objects are already part of the SQL Server replication. Right-click the configured publication of the database and Go to Publication properties where we will get a list of articles which are part of the SQL replication.

在添加新文章之前,首先,我们需要检查哪些数据库对象已经是SQL Server复制的一部分。 右键单击已配置的数据库发布,然后转到发布属性 ,我们将在其中获得属于SQL复制的文章列表。

In the following fig. articles which ticked are already part of SQL Server replication.

在下图。 勾选的文章已经是SQL Server复制的一部分。

Articles which are part of replication

The new articles which need to add into publication database, First, un-check Show only checked items in the list option as shown in the following fig. we will get a list of all the objects from the database. We will select new tables ProductCategory and ProductDescription from the following list and click OK.

需要添加到发布数据库中的新文章,首先,取消选中lis t选项中的“仅显示选中的项目”,如下图所示。 我们将从数据库中获取所有对象的列表。 我们将从下面的列表中选择新表ProductCategoryProductDescription ,然后单击OK。

Select articles which need to add

Once we added the new list of articles in the current publication, right-click Configured publication and select Reinitialize all Subscription as the following.

一旦我们在当前出版物中添加了新的文章列表,请右键单击“配置的出版物”,然后选择“ 重新初始化所有订阅 ”,如下所示。

Reinitialize all subscription

Click on the Use a new snapshot; this option will able to create a new snapshot till time and click on Mark for Reinitialization.

单击“ 使用新快照” ; 该选项将能够创建一个新的快照,直到出现时间,然后单击“ 标记为重新初始化”

Use a new snapshot

Right-click configured publication and Select Launch Replication Monitor.

右键单击配置的发布,然后选择启动复制监视器

Launch replication monitor

Go to Agent tab as shown in the following.

转到代理选项卡 ,如下所示。

Agent tab

Right-click on snapshot section and click start agent, this process will create a new snapshot after adding the new articles in the current publication and will be used for the further SQL replication process.

右键单击快照部分,然后单击启动代理 ,此过程将在当前出版物中添加新文章后创建一个新快照,并将用于进一步SQL复制过程。

Start agent

After running agent, we can check Last start time and last action and duration of snapshot run as shown in the following window.

运行代理后,我们可以检查快照的 上次启动时间上次操作快照的持续时间,如下窗口所示。

Last run and last action of the agent

After creating a new snapshot, we will verify the status of the snapshot agent. Right-click the publication and select View Snapshot Agent Status as the following.

创建新快照后,我们将验证快照代理的状态。 右键单击发布,然后选择“ 查看快照代理状态 ”,如下所示。

View snapshot agent status

Snapshot agent status is in a healthy state. A snapshot of 9 articles generated as shown on the following fig.

快照代理状态为健康状态。 生成的9个文章的快照,如下图所示。

Generated snapshot

After adding new articles in the current publication, we can verify that new articles have added to the subscriber server SQL2 as shown in the following fig.

在当前出版物中添加新文章之后,我们可以验证新文章已添加到​​订户服务器SQL2中,如下图所示。

New articles created on the subscriber

从出版物中删除表 (Drop Table from the publication)

In this section, we will learn about to drop a table from the publication.

在本节中,我们将学习从出版物中删除表格。

The table Customer of the database AdventureWorksLT_2012 is part of the SQL Server replication. We will try to drop it as the following; however, it will not allow us to drop it because a table configured as an article in the SQL replication and It will throw an error as shown in the following.

数据库AdventureWorksLT_2012的 客户表是SQL Server复制的一部分。 我们将尝试如下删除它; 但是,它不允许我们删除它,因为在SQL复制中配置为项目的表会引发错误,如下所示。

Drop article from the publisher

Before dropping a table, first, we need to remove a table from the publication. Right-click publication and Go to Publication Properties. So, we want to drop a table Customer, so Let’s uncheck it from the list of objects to publish section. Once we uncheck it, we will get a pop-up warning click Yes.

在删除表之前,首先,我们需要从发布中删除表。 右键单击发布,然后转到发布属性 。 因此,我们要删除一个表Customer ,因此让我们从要发布的对象列表中取消选中它。 取消选中它后,我们将弹出警告,单击

Uncheck article

Once clicked on Yes, we will get a pop-up to create a new snapshot. Select Use a new snapshot and click Mark for Reinitialization.

单击“是”后,我们将弹出一个窗口以创建一个新快照。 选择“ 使用新快照”然后单击“ 标记为重新初始化”

Use a new snapshot

Right-click publication and Go to Replication monitor. Right-click view details.

右键单击发布,然后转到“复制”监视器 。 右键单击查看详细信息

View Details of the snapshot

The following section gives us the history of the snapshot agent. The next part shows nine articles have generated after removing one article from the publication.

下一节为我们提供了快照代理的历史记录。 下一部分显示从出版物中删除一篇文章后生成的九篇文章。

History of snapshot agent

Right-click publication and click Reinitialize

用鼠标右键单击发布,然后单击重新初始化

Reinitialize subscription

Click Use the current snapshot to reflect the results on the subscriber.

单击“ 使用当前快照以将结果反映到订阅服务器上”。

use the current snapshot

Drop the table on the publisher SQL1 as the following

将表放在发布服务器SQL1上,如下所示

drop table

On the subscriber SQL2, we can verify the table removed from the subscriber.

在订户SQL2上,我们可以验证从订户中删除的表。

Articles on subscriber

更改快照文件夹路径 (Change Snapshot folder Path)

While configuring SQL Server Distribution database, we had given the following snapshot folder path. In this section, we will learn to change the snapshot folder path in the from the current distribution.

在配置SQL Server Distribution数据库时,我们给出了以下快照文件夹路径。 在本节中,我们将学习从当前发行版更改的快照文件夹路径。

snapshot folder path

Right-click publication and Go to properties.

右键单击发布,然后转到属性

Publication properties

Go to Snapshot page on the left side and check current snapshot files path.

转到左侧的“ 快照”页面 ,并检查当前快照文件的路径。

location of snapshot files

To change the path, Right-click Replication folder and click Distribution Properties.

要更改路径,请右键单击“复制”文件夹 ,然后单击“ 分发属性”

Distributor properties

In the Publisher page section, click on the icon in the following fig.

在“发布者”页面部分中,单击下图中的图标。

Publisher icon

Provide the new correct path and click OK

提供新的正确路径,然后单击“ 确定”。

Change the Snapshot folder path

资料筛选器 (Data Filter)

SQL Server replication provides an excellent feature to filter the data using the Column data filter. In the data filter, we will able to show the column which we want to display for the reposting purpose. We can remove the column which contains sensitive information like customer name, customer email, credit card, etc.

SQL Server复制提供了一项出色的功能,可以使用列数据筛选器筛选数据。 在数据过滤器中,我们将能够显示要重新发布的列。 我们可以删除包含敏感信息的列,例如客户名称,客户电子邮件,信用卡等。

In the project environment, we build a dashboard in the tableau framework. Client vendors used to access those tableau dashboards for data analysis purposes. In that, we want to show data information of the one particular vendor to that specific vendor only. We do not want to show one vendor information to another vendor. So to limit data visibility, we will set-up SQL Server replication with data filter option.

在项目环境中,我们在tableau框架中构建一个仪表板。 客户端供应商过去曾访问这些Tableau仪表板以进行数据分析。 这样,我们只想向该特定卖方显示一个特定卖方的数据信息。 我们不想将一个供应商信息显示给另一供应商。 因此,为了限制数据可见性,我们将使用数据过滤器选项设置SQL Server复制。

Once the distribution database configured, we will proceed to set the publication.

配置分发数据库后,我们将继续设置发布。

Right-click Replication folder and select New Publication. Select the database AdventureWorksLT2012 as the following and click Next

右键单击复制文件夹,然后选择新建发布 。 选择数据库AdventureWorksLT2012 ,如下所示,然后单击“下一步”。

Select database

Select the required database objects and click Next

选择所需的数据库对象,然后单击“ 下一步”。

Select articles

In the Filter Table Rows window, if we do not want to filter data, we can skip this step. Now we need to filter data so that we will configure this section window. Click on Add as shown in the following.

在“ 过滤表行”窗口中,如果不想过滤数据,则可以跳过此步骤。 现在我们需要过滤数据,以便我们配置此部分窗口。 单击添加 ,如下所示。

Add filter table rows

Select the table we need to use for the data filter. We selected the table Customer from the SalesLT schema. Next, we need to add the column which contains sensitive information on the right-side filter statement. We will apply the condition for the specified column, and it will show the results only for the conditional statement.

选择我们需要用于数据过滤器的表。 我们从SalesLT模式中选择了表Customer 。 接下来,我们需要在右侧的filter语句上添加包含敏感信息的列。 我们将条件应用于指定的列,并且它将仅显示条件语句的结果。

In this case, we added the column CompanyName for the condition; company name starts with A

在这种情况下,我们为条件添加了CompanyName列; 公司名称以A开头

Apply filter condition

Once we added the table Customer in the filter section as shown in the following fig.

一旦我们在过滤器部分中添加了表Customer ,如下图所示。

Filtered tables

In the Snapshot section, select a checkbox for Create a snapshot and click Next.

在“ 快照”部分中 ,选中“ 创建快照”复选框,然后单击“ 下一步”

Create a snapshot

In the Agent Security, configure the service account for the snapshot agent and the log reader agent as the following and click Next.

在“ 代理安全性”中 ,如下配置快照代理和日志读取器代理的服务帐户,然后单击“下一步”。

configure service account

In the complete wizard window, provide publication name as the following and click Finish.

完整的向导窗口中 ,提供以下发布名称,然后单击“ 完成”

Provide Publication name

Publication is configured successfully as the following.

发布成功配置如下。

Creating Publication

订户上的数据验证 (Data Verification on the Subscriber)

In this step, we will verify the data; On the Publisher server SQL1, we will retrieve records from the table Customer. We can see, the column CompanyName shows the values for all the company name.

在这一步中,我们将验证数据; 在发布服务器SQL1上,我们将从表Customer中检索记录。 我们可以看到, CompanyName列显示了所有公司名称的值。

CompanyName records on publisher

In this step, we will verify the data on the Subscriber server SQL2. When we retrieved records for the same table on the subscriber server SQL2, we will get filter data for the condition which we have specified in the filter section. We got the company name which starts with only character A as shown in the following fig.

在此步骤中,我们将验证订阅服务器SQL2上的数据。 当我们在订阅服务器SQL2上检索同一表的记录时,我们将获得在filter部分中指定的条件的过滤器数据。 我们得到的公司名称仅以字符A开头,如下图所示。

Filtered records on Subscriber

目录 (Table of contents)

SQL Server replication configuration: Peer to Peer and Merge Replication
SQL Server replication: Configuring Snapshot and Transactional Replication
Add new articles, drop the article, change the snapshot folder path and Data filter rows in SQL Server Replication
SQL Server复制配置:点对点和合并复制
SQL Server复制:配置快照和事务复制
添加新文章,删除文章,更改快照文件夹路径和SQL Server复制中的数据筛选器行

翻译自: https://www.sqlshack.com/add-new-articles-drop-the-article-change-the-snapshot-folder-path-and-data-filter-rows-in-sql-server-replication/

sql server 快照

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值