SQLServer parses each object of the NotforReplication Application

Source: Internet
Author: User
NotforReplication is an attribute that can be applied to objects (such as Check constraints, foreign key constraints, triggers, and IdentityColumn) in SQLServer replication. This feature is used when the database administrator wants to make the transaction behavior different between the replication proxy and the general user transaction in the case of data modification changes.

Not for Replication is an attribute that can be applied to objects (such as Check constraints, foreign key constraints, triggers, and Identity columns) in SQL Server Replication. This feature is used when the database administrator wants to make the transaction behavior different between the replication proxy and the general user transaction in the case of data modification changes.

"Not for Replication" is an attribute that can be applied to various objects (such as Check constraints, foreign key constraints, triggers, and Identity Column-Identity Column) in SQL Server Replication. This feature is used when the administrator wants to make the transaction behavior different in two situations: data modification and change from replication proxy to normal user transaction.

Example

A company has multiple sales points throughout the country. Each sales point obtains orders from end users and copies requests to the products and distribution department of the company.

The products and distribution department of the company act as the publisher, and each sales point acts as the subscriber to build a consolidated replication architecture. Each sales point contains information about the current inventory level of the product. When the commodities in the master database are sold out, the sales point will no longer accept new orders.

The table in the replication topology is as follows: Products is the parent table and is connected to the Orders table using the primary key-foreign key constraint in the Product_id column. The Product table also contains a column named Stock_Available to track the current inventory of the Product.

Products table:

Orders table:

In addition, there is an after insert trigger ("Update_Stock") on the Orders table to check whether there is sufficient inventory for the product corresponding to a product_id. If yes, it will update the Products table and subtract the quantity from the current inventory.

Trigger example:

Create TRIGGER [dbo]. [Update_Stock]

ON [dbo]. [Orders]

AFTER INSERT

AS

BEGIN

Declare @ quantity as int

Declare @ product_id as int

Declare @ stock_available as int

Select @ product_id = product_id, @ quantity = quantity from Inserted

Select @ stock_available = stock_available from Products where product_id = @ product_id

If (@ Quantity> @ stock_available)

Rollback

Else

Update Products set stock_available = stock_available-@ quantity where product_id = @ product_id

END

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.