Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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: 772 | Views in the last 30 days: 14
Related Articles

Disable foreign constraint

Disable foreign constraint


Foreign Key Constraints and Performace!

Do foreign keys constraints impact performance?


Rename Foreign Key Constraints

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


Suggestion on Foreign Key Constraint

Suggestion on whether to add Foreign Key Constraint or Not


A Check and Foreign Key Constraint Improves Query Performance

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


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones