Retrying an INSERT can create duplicate rows even with an identity primary key. These tested examples use a stable request ID to return the original order, reject changed inputs, and preserve unrelated errors.
SQL SERVER – Drop All the Foreign Key Constraint in Database – Create All the Foreign Key Constraint in Database
Need to drop all the foreign key constraints in a database and create them again? Here is a script by SQL expert Swastik Mishra that does both.
Assertion Queries: Data Checks That Should Return Zero Rows
Let a short query find the order with no lines before a customer does. A small demo shows the failing keys, constraint error 547 and a clean repair.
SQL SERVER – Listing Primary Key of Table with Stored Procedure sp_pkeys
Here is how to list the primary key of a table with the stored procedure sp_pkeys, a follow up to my earlier post on sp_fkeys.
SQL SERVER – Listing Foreign Key Relationships of Table with Stored Procedure sp_fkeys
A quick trick to list all the foreign key relationships of a table with the stored procedure sp_fkeys, with a sample script on AdventureWorks2012.
Stopping Duplicate API Requests With an Idempotency Key Table
Store an idempotency key with its order in one transaction, return the committed result on retries, and define key reuse and expiry rules.
SQL SERVER – Create Unique Constraint on Table Column on Existing Table
Can you create unique constraint on a column of a table that already exists? Yes. Here is the short ALTER TABLE ADD CONSTRAINT script I use.






