This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
Two beach towels thrown onto one empty deckchair at once, a cream towel covering the seat and a red one sliding off.

Handling Duplicate Key Errors 2627 and 2601 in a CATCH Block

April 15, 2021
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL Error Messages, SQL Server, SQL Transactions

Handle duplicate key errors 2627 and 2601 in TRY CATCH, preserve unexpected errors, and avoid racing existence checks during inserts.

Read More
An engaged fitting clamp remains separate from older pieces awaiting inspection.

SQL SERVER – Find Untrusted Foreign Key

March 3, 2021
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL Scripts, SQL Server, SQL Server Security

An Untrusted Foreign key has not validated all existing rows. A customer bulk-load history prompted this inventory.

Read More
Gouache painting of a small blank cream luggage tag tied with a vermilion string to the handle of a brown suitcase, a second suitcase standing behind it

Error 2714: There Is Already an Object Named MyFirstTable

February 23, 2021
Pinal Dave
SQL Tips and Tricks
Primary Key, SQL Constraint and Keys, SQL Error Messages, SQL Scripts

Error 2714 reported that MyFirstTable already existed, but the client found no such table. A query on sys.objects showed a primary key constraint with that name on another table. Creating the table under another name, or renaming the key, fixes it.

Read More
Gouache painting of a sorter board with round beads and a rejected square vermilion block

Digits in a Column: A CHECK Constraint for Digits Only

February 1, 2021
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL Scripts, SQL Server, SQL String

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.

Read More
Three vessels retain a supplied tag, an older tag and an empty tag loop.

SQL SERVER – Capturing INSERT Timestamp in Table

November 23, 2020
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL DateTime, SQL Scripts, SQL Server

A default can insert timestamp values when the caller omits a datetime column. I use a session-local CURRENT_TIMESTAMP example.

Read More
An existing overgrown garden section remains beside newly planted orderly seedlings

How to Add Constraint With No Validation? – Interview Question of the Week #299

October 25, 2020
Pinal Dave
SQL Interview Questions and Answers
SQL Constraint and Keys, SQL Error Messages, SQL Identity, SQL Scripts, SQL Server

Question: How to Add Constraint With No Validation?

Answer: I got this question from one of my clients of who is an Oracle user.

Read More
Gouache painting of three padlocks on a bench, each with a vermilion key in it

Check Constraint on Identity Column: Why Inserts Fail

October 24, 2020
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL Identity, SQL Scripts

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.

Read More
Previous 1 2 3 4 5 … 25 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com