> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqlbuild.com/llms.txt
> Use this file to discover all available pages before exploring further.

# diff

> Compare schemas and data between targets or virtual environments.

Compares schemas and optionally row-level data between two build contexts: two targets (e.g. `prod:dev`) in standard mode, or two virtual environments when virtual mode is enabled. See [Data Diffs](/concepts/diff) for detailed usage.

## Usage

```bash theme={null}
sqb diff <FROM>:<TO> <mode> [flags]
```

The first argument is a positional `FROM:TO` range. Exactly one mode is required: `--full`, `--schema-only`, or `--bounded <duration>`.

Full and bounded row comparisons require the model to define `unique_key`. Bounded mode uses the model's cursor and falls back to a full row comparison when no cursor is configured.

## Flags

| Flag                      | Description                                                |
| ------------------------- | ---------------------------------------------------------- |
| `--full`                  | Compare both schema and all row data                       |
| `--schema-only`           | Compare column names and types only                        |
| `--bounded`               | Compare row data within a recent window (e.g. `14d`, `6h`) |
| `--verbose`, `-v`         | Show more example rows (default: 3, verbose: 10)           |
| `--max-column-examples`   | Override maximum examples per changed column               |
| `--max-row-only-examples` | Override maximum examples for side-only rows               |
| `--no-sql-validation`     | Skip compile-time SQL syntax validation                    |
| `--select`, `-s`          | Select specific models to diff (required in v1)            |
| `--exclude`               | Exclude specific models from diffing                       |

## Examples

```bash theme={null}
# Full diff of a specific model
sqb diff prod:dev --full --select customer_status_snapshot

# Schema-only diff of all marts
sqb diff prod:dev --schema-only --select path:models/marts

# Bounded diff of last 14 days
sqb diff prod:dev --bounded 14d --select hourly_order_activity
```

## Exit codes

Returns `0` when all selected models have no differences, `1` when any model has schema or row differences.
