SQL Server 复制触发器
我需要创建一个 SQL Server 数据库,它将通过某种复制机制从另一个数据库接收更新。 我需要编写插入、更新和删除触发器,这些触发器将在复制发生时执行。
我有触发器方面的经验,但没有复制方面的经验。
我应该使用事务复制还是合并复制,或者这很重要吗?
设计为在执行简单 SQL 插入语句时运行的触发器也会在复制发生时运行吗?
I need to create a SQL Server database that will recieve updates by some replication mechanism from another database. I need to write insert, update and delete triggers that will execute when this replilcation occurs.
I have experience with triggers but not with replication.
Should I use Transactional or Merge replication, or does it matter?
Will a trigger designed to run when a simple SQL insert statement is executed also run when replication occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MSDN 上的 CREATE TRIGGER 语法:
这表明在复制上执行是触发器的默认行为,可以通过指定 NOT FOR REPLICATION 来禁用。
The CREATE TRIGGER syntax on MSDN:
This indicates that executing on replication is the default behaviour for triggers, and can be disabled by specifying
NOT FOR REPLICATION
.这得看情况。
如果您打算应用的更新是独立表,即给定表的所有数据仅来自发布者,那么您可以使用事务复制。
另一方面,如果您希望将表内容(即订单表)与在两个站点下达的订单结合起来,那么您可能需要考虑使用合并复制。
关于触发器,有一个“不用于复制”配置,您可以应用它来控制它们的行为。 请参阅以下文章以供参考。
http://msdn.microsoft.com/en-us/library/ms152529。干杯
,约翰
Well it depends.
If the updates that you intend to apply are to isolated tables i.e. all the data for a given table comes from the publisher only, then you can use transactional replication.
If on the other hand you are looking to combine table content i.e. an orders table, with orders being placed at both sites, then you would want to look into using merge replication.
With regard to triggers, there is a "not for replication" configuration that you can apply to control their behaviour. See the following article for reference.
http://msdn.microsoft.com/en-us/library/ms152529.aspx
Cheers, John
仅凭您提供的信息很难回答您的问题。 我在您的问题中添加了一些评论,要求澄清信息。
以下是 MSDN 上的一篇文章,应该会有所帮助:http://msdn.microsoft。 com/en-us/library/ms152529.aspx
默认情况下,触发器将在复制期间触发,除非指定“NOT FOR REPLICATION”。 它们的工作方式与简单插入语句的工作方式相同。
事务复制和合并复制非常不同,但触发器对于这两个选项的行为相似。
It's hard to answer your question with the information you've provided. I added a few comments to your question asking for clarifying information.
Here is an article on MSDN that should help: http://msdn.microsoft.com/en-us/library/ms152529.aspx
By default, triggers will fire during replication unless "NOT FOR REPLICATION" is specified. They work the same way as they do for simple insert statements.
Transactional and Merge replication are very different, but triggers behave similarly for both options.
除了触发器之外,还有一些替代选项可供您选择。
There are a few alternative options open to you instead of triggers.