Quantcast
Channel: SQL Server Replication forum
Viewing all articles
Browse latest Browse all 4054

Why foreign key not for replication is_not_trusted

$
0
0

Hi,

Why when I define FK not for replication" is_not_trusted=1?   even the table is not replicated at all.

What is the sense in it?

here is a script to illustrate it :

CREATE TABLE Persons
(P_Id int NOT NULL,
 somecolumn varchar(10)
CONSTRAINT PK_Persons PRIMARY KEY CLUSTERED (P_Id ASC)
)
CREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
CONSTRAINT PK_Orders PRIMARY KEY CLUSTERED (O_Id ASC),
CONSTRAINT FK_Orders_Persons FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) NOT FOR REPLICATION
)
CREATE TABLE OrderLines
(
O_Id int NOT NULL,
Line_Id int NOT NULL,
Amount int,
CONSTRAINT PK_OrderLines PRIMARY KEY CLUSTERED (O_Id ASC, Line_Id),
CONSTRAINT FK_OrderLines_Orders FOREIGN KEY (O_Id) REFERENCES Orders(O_Id)
)
 
SELECT name, is_not_trusted, is_not_for_replication FROM sys.foreign_keys WHERE name IN ('FK_Orders_Persons','FK_OrderLines_Orders')

ALTER TABLE Orders WITH CHECK CHECK CONSTRAINT FK_Orders_Persons; 

SELECT name, is_not_trusted, is_not_for_replication FROM sys.foreign_keys WHERE name IN ('FK_Orders_Persons','FK_OrderLines_Orders')

ALTER TABLE OrderLines NOCHECK CONSTRAINT FK_OrderLines_Orders
SELECT name, is_not_trusted, is_not_for_replication FROM sys.foreign_keys WHERE name IN ('FK_Orders_Persons','FK_OrderLines_Orders')

ALTER TABLE OrderLines WITH CHECK CHECK CONSTRAINT FK_OrderLines_Orders
SELECT name, is_not_trusted, is_not_for_replication FROM sys.foreign_keys WHERE name IN ('FK_Orders_Persons','FK_OrderLines_Orders')


Regards, Asi Pesa


Viewing all articles
Browse latest Browse all 4054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>