📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is an untrusted constraint in SQL Server, how does it happen, and why does it matter?

Junior Theory Beginner

🎯 Key points

  • is_not_trusted = 1 in sys.foreign_keys / sys.check_constraints
  • Caused by WITH NOCHECK on create or re-enable
  • New writes still checked; existing rows may violate it
  • Optimiser loses join elimination and contradiction detection
  • Find and fix violating rows before re-validating
  • WITH CHECK CHECK CONSTRAINT scans the table: schedule it

⏱ 30-second answer

A constraint is untrusted when is_not_trusted = 1 in sys.foreign_keys or sys.check_constraints. It happens when it is created WITH NOCHECK, or re-enabled with ALTER TABLE ... CHECK CONSTRAINT (which defaults to WITH NOCHECK), typically after a bulk load or a migration that disabled constraints.

Effects: new writes are still checked, but existing rows were never validated, so orphans or invalid values may already be there and reports or joins can return wrong results. The optimiser cannot rely on it, so it loses join elimination and contradiction detection.

Fix: find the violating rows (e.g. LEFT JOIN to the parent where it is NULL), delete, correct or re-parent them, then run ALTER TABLE t WITH CHECK CHECK CONSTRAINT c. It scans the table under a schema lock, so schedule it off-peak on large tables.

🔍 What the interviewer is checking

Checks knowledge of WITH NOCHECK and the optimiser's use of trusted constraints.

↩ Usually asked after

More in Database Design

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me