Handle duplicate key errors 2627 and 2601 in TRY CATCH, preserve unexpected errors, and avoid racing existence checks during inserts.
SQL SERVER – Find Untrusted Foreign Key
An Untrusted Foreign key has not validated all existing rows. A customer bulk-load history prompted this inventory.
Digits in a Column: A CHECK Constraint for Digits Only
To keep only digits in a column, a CHECK constraint with NOT LIKE and a character range works, but it has two holes. It accepts an empty string and digits from other scripts. A demo closes both and shows NULL, trust and fixed length codes.
SQL SERVER – Capturing INSERT Timestamp in Table
A default can insert timestamp values when the caller omits a datetime column. I use a session-local CURRENT_TIMESTAMP example.
Check Constraint on Identity Column: Why Inserts Fail
A check constraint on identity column values can make every insert fail, because the identity moves on whether or not the row is accepted. This post reproduces the failure, shows that the failed attempts still use up identity values, and lists every such constraint in a database with one query.







