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
Five rows of ID boxes. At the start the IDs are 1 to 5. After deleting 4 and 5, a new row gets ID 6. After restoring 4 and 5 with IDENTITY_INSERT on, the next new row gets ID 7

Overriding Identity Fields: Put a Deleted Row Back With Its Old ID

August 9, 2011
Pinal Dave
SQL Tips and Tricks
SQL Constraint and Keys, SQL Identity, SQL Scripts, SQL Server

Overriding identity fields is rare, but restoring a deleted row with its old ID needs it. This post uses IDENTITY_INSERT to put two workshops back with their old numbers. It shows the five errors you will meet, what happens to the next automatic number, and why gaps in an identity column are usually fine.

Read More
Three tables side by side. Orders has four rows and Plants has five rows. The OrderItems table between them has seven rows, and each row pairs one order number with one plant number and a quantity

Many-to-Many Bridge Table in SQL Server: Model and Query It

August 8, 2011
Pinal Dave
SQL Tips and Tricks
Normalization, SQL Constraint and Keys, SQL Joins, SQL Scripts

A many-to-many bridge table links two tables that each have many partners in the other, such as orders and plants. This post builds one with a composite key and two foreign keys, then joins it three ways. It also shows what the keys block and why an inner join hides plants nobody ordered.

Read More
Timeline of one update that is rolled back after 12 seconds and five readers that start after 3 seconds. The default reader waits 9 seconds and sees 24.00. READUNCOMMITTED and NOLOCK see 240.00 at once. READPAST skips the locked row. NOWAIT fails with Msg 1222. With row versioning on, the default reader sees 24.00 at once

Dirty Records and Table Hints: Wait, Read Dirty, Skip or Fail

August 7, 2011
Pinal Dave
SQL Tips and Tricks
SQL Lock, SQL Scripts, SQL Transactions, Transaction Isolation

Dirty records and table hints decide what a SELECT does while another session has an uncommitted change. This post runs one update that rolls back and five readers against it: the default, READUNCOMMITTED, NOLOCK, READPAST and NOWAIT. It also shows how a database option changes the default.

Read More
Two panels comparing separate INSERT statements with one multi-row INSERT when book 4 is a duplicate key. Separate statements save book 11 and leave 9 books. The multi-row INSERT saves nothing and leaves 8 books

Multi-Row INSERT in SQL Server: One Statement, All or Nothing

August 6, 2011
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Server, SQL Table Operation, SQL Transactions

A multi-row INSERT adds several rows with one statement, using a list of value groups separated by commas. This post compares it with separate INSERT statements on a small table of books. It shows that one bad row undoes the whole statement, and it covers the errors and the 1,000 row limit.

Read More
Result of a LEFT JOIN from six plants to their order lines. Orchid, Bamboo and Mint show NULL in the LineID column, and the filter LineID IS NULL keeps only those three

Unmatched Records Query: Four Ways to Find Rows With No Match

August 5, 2011
Pinal Dave
SQL Tips and Tricks
SQL Joins, SQL NULL, SQL Scripts, SQL Sub Query

An unmatched records query finds the rows in one table that have no partner in another, such as plants that never sold. This post runs four versions on a small table: LEFT JOIN with a NULL test, NOT EXISTS, NOT IN and EXCEPT. It also shows the NULL trap that makes NOT IN return nothing.

Read More
Two boxes joined by an arrow. Phase one, organize, runs SELECT star in three steps that return 4, 7 and 5 rows. Phase two, itemize, swaps the star for a column list and returns the same 5 rows

Build a Query in Two Phases: Organize First, Itemize Second

August 4, 2011
Pinal Dave
SQL Tips and Tricks
Best Practices, SQL Coding Standards, SQL Joins, SQL Scripts

Build a query in two phases: organize first, itemize second. Phase one gets the tables, joins and filter working with SELECT *, and phase two swaps the star for a column list. This post shows the method on a small branch and staff table, and the three errors it helps you avoid.

Read More
Table of eight shop names with the character code of each apostrophe and whether LIKE found it. Three straight marks, code 39, were found. Two curly marks, code 8217, were not found

Finding Apostrophes in SQL Server Text: Straight and Curly

August 3, 2011
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Search, SQL String, Unicode

Finding apostrophes in SQL Server text takes one trick and one trap. The trick is doubling the quote inside a LIKE pattern. The trap is that text can hold a curly apostrophe, and the usual search skips it. This post tests both on a table of eight shop names.

Read More
Previous 1 … 582 583 584 585 586 587 588 … 844 Next
  • Books
  • Testimonials
  • Privacy Policy

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