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