The SQL Booklet · Development and exploration

Understand a database.

Twenty-two queries for locating objects, reconstructing relationships, validating data, and making changes with a visible scope.

A guided path

Exploration guided by a question.

Each entry begins with something we need to locate or distinguish: a table mentioned in an error, a column whose origin is unknown, a dependency, a difference between sets, or the actual scope of a change.

The path moves from metadata and relationships toward data validation and controlled modifications. The queries reduce the investigation space. The model, permissions, and deployment history complete the context.

How to use it

Evidence for exploration and change.

  1. Define the object or scopeLimit the database, table, pattern, or set that you actually need to investigate.
  2. Read metadata in contextVisibility depends on permissions. Identifying who made a change requires evidence beyond a recorded date.
  3. Validate before converting or modifyingIdentify problematic rows and compare the intended set with the result.
  4. Keep a verifiable outputControlled changes show target rows, previous values, and the result before confirmation.

Editorial method

The scope of each query.

Examples avoid claiming that a catalog or system view contains the complete history of a database. Each entry explains which conclusion can be drawn and which additional evidence is still missing.

Write operations use filters, limits, row checks, and controlled rollback. Before adapting a query, permissions, cost, potential blocking, and dependencies are reviewed.

Read the editorial methodology

The path

Five exploration sections.

The order begins with visible structure, continues with data quality, and ends with comparisons and delimited operations.

Section 1

Locate objects and relationships

Queries for reconstructing names, columns, dependencies, keys, indexes, and triggers in an existing database.

  1. 01Search for a table or view by name
  2. 02Search for a column across the database
  3. 03Search for text inside procedures, views, and functions
  4. 04Inspect the dependencies of an object
  5. 05List relationships and foreign keys
  6. 06Inspect primary keys, unique constraints, and indexes
  7. 07List columns with type, length, nullability, and default value
  8. 08Find triggers and their associated tables
Section 2

Recognize size and state

Modification dates, approximate row counts, used space, and IDENTITY columns.

  1. 09Find recently modified objects
  2. 10Get approximate row counts for every table
  3. 11Measure the space used by each table
  4. 12Inspect IDENTITY columns and their current value
Section 3

Check data quality and compatibility

Duplicates, orphaned rows, differences between sets, and conversions that may fail.

  1. 13Find duplicate rows by business key
  2. 14Find orphaned rows
  3. 15Compare two data sets
  4. 16Validate conversions before changing a column
Section 4

Modify with control

UPDATE and DELETE examples that delimit the target, preserve evidence, and roll back by default.

  1. 17Run an UPDATE with controlled validation and rollback
  2. 18Run a DELETE with a logical backup and controlled rollback
Section 5

Compare and describe

Structures across databases, result metadata, tables without a primary key, and targeted value searches.

  1. 19Compare the structure of two databases
  2. 20Describe the result of a query or stored procedure
  3. 21Find tables without a primary key
  4. 22Search selected columns for a value