Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Re-Trust Untrusted Foreign Keys and Constraints

By Shaun J. Stuart,

Foreign keys and constraints sometimes are disabled during bulk data loads. Simply re-enabling the foreign key or constraint leaves it in an untrusted state. In order for SQL Server to utilize the key or constraint in query plans, it must be verified. This script will find all enabled, untrusted foreign keys and attempt to verify them and make them trusted. It will report counts of the number of foreign keys it could and could not re-trust.

The same script can be used to validate constraints by changing the first table in the cursor FROM clause from sys.foreign_keys to sys.check_constraints.

Total article views: 850 | Views in the last 30 days: 16
 
Related Articles
FORUM

Disable foreign constraint

Disable foreign constraint

FORUM

Foreign Key Constraints and Performace!

Do foreign keys constraints impact performance?

SCRIPT

Rename Foreign Key Constraints

Rename Foreign Key Constraints in a consistent manner. Ideal for preventing constraint errors durin...

FORUM

Suggestion on Foreign Key Constraint

Suggestion on whether to add Foreign Key Constraint or Not

ARTICLE

A Check and Foreign Key Constraint Improves Query Performance

Check and foreign key constraint do not degrade performance but actually improve it.

Tags
 
Contribute