A likely cause of untrusted constraints is bulk insert operations without the CHECK_CONSTRAINTS option. Capture the bulk_insert_usage, databases_bulk_copy_rows, and databases_bulk_insert_rows events along with the statement and other information needed to identify the culprit.
Extended Events to trace Foreign Keys becoming untrusted
I am trying to find out what is continually setting the Foreign Keys and Constraints to untrusted. I've setup an Extended Events session to trap Alter Table events but it's not catching it. How can I trap this using Extended Events?
WHERE ([sqlserver].like_i_sql_unicode_string
3 answers
Sort by: Most helpful
-
-
Erland Sommarskog 112.7K Reputation points MVP
2020-08-21T21:55:57.993+00:00 I would rather use a DDL trigger to capture this. I can't think of any command but ALTER TABLE that can cause an FK constraint to be untrusted, but I have a feeling that there can be one. So I would start with capturing all DDL events and just insert the output of eventdata() to a table. If there is a lot of DDL activity in the database, you may have to refine it.
-
Cris Zhan-MSFT 6,636 Reputation points
2020-08-27T07:28:46.713+00:00 Hi,
Untrusted constraints can be found when you alter/drop foreign key relationships and then add them back without the proper syntax.
https://www.brentozar.com/blitz/foreign-key-trusted/
https://wateroxconsulting.com/archives/untrusted-foreign-keys/