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

# CHECK TABLE

Checks one or more *tables* for corrupted data, by reading every column of every
chunk of each *table* from disk, on every rank.  Chunks whose data cannot be read
are reported and marked as corrupt.

Checking a *table* requires read
[permission](https://docs.kinetica.com/content/security/sec_concepts.md#security-concepts-permissions) on it; *tables* the
user cannot read are skipped without error, as are *views*.

```sql title="CHECK TABLE Syntax" theme={null}
CHECK TABLE[S] < [<schema name>.]<table name>[,...] | * >
[WITH OPTIONS (<option name> = '<option value>'[,...])]
```

> [!WARNING]
>
> `CHECK TABLE` only reads data, but any chunks it finds to be
> corrupt are marked as such, and, by default, the database then repairs them
> automatically in the background:  each corrupted chunk is truncated to a
> consistent length or, if that fails, deleted, and the records lost are not
> recoverable.  To review any corruption before data is removed, set
> `wal.auto_truncate_corrupt_tables` to `false` in the
> [system configuration](https://docs.kinetica.com/content/config.md) and repair the *table*
> with [REPAIR TABLE](https://docs.kinetica.com/content/sql/ddl/repair-table.md).  Until a *table* marked as corrupt is repaired, reads
> from and deletes on it fail.

Because `CHECK TABLE` loads every column of each *table* into memory, checking
large *tables* can take a long time and can displace data that other queries are
using.  Queries can read a *table* while it is being checked, but some changes to
the *table* wait until its check is complete.  Consider checking large *tables*,
or all *tables* with `*`, during a period of low activity.

## Parameters

> **\<schema name>**
>
> Name of the *schema* containing the *table* to check

> **\<table name>**
>
> Name of the *table* to check; multiple *tables* can be given as a comma-separated list

> ***
>
> Check all *tables*

> **WITH OPTIONS**
>
> Optional indicator that a comma-delimited list of option/value assignments will follow; see
> the options below

## Options

> **LOCAL\_ONLY**
>
> If `true`, only check column data that has a copy in the local
> [persist tier](https://docs.kinetica.com/content/rm/concepts.md#rm-concepts-tiers-persist); data held only in cold storage is skipped,
> and so is not checked.  The default is `false`, which downloads data held only in cold
> storage in order to check it.

> **SHOW\_DETAIL**
>
> If `true` (the default), report each corrupted chunk individually.  If `false`, report only
> a count of the corrupted chunks found for each *table* at each location.

## Response

`CHECK TABLE` returns rows only for *tables* with corrupted data; a *table*
with no corruption produces no rows.  By default, each row describes one
corrupted chunk; with `SHOW_DETAIL` set to `false`, each row summarizes the
corrupted chunks of one *table* at one location.

| Output Column | Description |
| - | - |
| `table_name` | Name of the *table* with corrupted data |
| `id` | Identifier of the corrupted chunk (`ChunkId:<n>`); empty when `SHOW_DETAIL` is `false` |
| `location` | Rank (and, on ranks with more than one TOM, the TOM) holding the corrupted data, in the form `Rank:<rank>` or `Rank:<rank>,Tom:<tom>` |
| `error` | Description of the error found in the chunk; when `SHOW_DETAIL` is `false`, the number of corrupted chunks found for the *table* at that location |

## Examples

To check two *tables* for corrupted data:

```sql CHECK TABLE Example theme={null}
CHECK TABLES example.rt_product, example.rt_order
```

To check a *table*, reporting only a count of corrupted chunks for each location
and skipping data held only in cold storage:

```sql CHECK TABLE with Options Example theme={null}
CHECK TABLE example.rt_product
WITH OPTIONS (SHOW_DETAIL = 'false', LOCAL_ONLY = 'true')
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.