# ConstraintFinderInterface

> ConstraintFinderInterface defines methods for getting a table constraint information.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › ConstraintFinderInterface

| interface | `yii\db\ConstraintFinderInterface` |
| --- | --- |
| Since | 2.0.14 |
| Source | [`framework/db/ConstraintFinderInterface.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/ConstraintFinderInterface.php#L17) |

Implemented by 5 types:

- [`yii\db\mssql\Schema`](/docs/api/yii/db/mssql/schema/index.md)
- [`yii\db\mysql\Schema`](/docs/api/yii/db/mysql/schema/index.md)
- [`yii\db\oci\Schema`](/docs/api/yii/db/oci/schema/index.md)
- [`yii\db\pgsql\Schema`](/docs/api/yii/db/pgsql/schema/index.md)
- [`yii\db\sqlite\Schema`](/docs/api/yii/db/sqlite/schema/index.md)

ConstraintFinderInterface defines methods for getting a table constraint information.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getSchemaChecks()`](#method-getSchemaChecks) abstract | Returns check constraints for all tables in the database. | `ConstraintFinderInterface` |
| [`getSchemaDefaultValues()`](#method-getSchemaDefaultValues) abstract | Returns default value constraints for all tables in the database. | `ConstraintFinderInterface` |
| [`getSchemaForeignKeys()`](#method-getSchemaForeignKeys) abstract | Returns foreign keys for all tables in the database. | `ConstraintFinderInterface` |
| [`getSchemaIndexes()`](#method-getSchemaIndexes) abstract | Returns indexes for all tables in the database. | `ConstraintFinderInterface` |
| [`getSchemaPrimaryKeys()`](#method-getSchemaPrimaryKeys) abstract | Returns primary keys for all tables in the database. | `ConstraintFinderInterface` |
| [`getSchemaUniques()`](#method-getSchemaUniques) abstract | Returns unique constraints for all tables in the database. | `ConstraintFinderInterface` |
| [`getTableChecks()`](#method-getTableChecks) abstract | Obtains the check constraints information for the named table. | `ConstraintFinderInterface` |
| [`getTableDefaultValues()`](#method-getTableDefaultValues) abstract | Obtains the default value constraints information for the named table. | `ConstraintFinderInterface` |
| [`getTableForeignKeys()`](#method-getTableForeignKeys) abstract | Obtains the foreign keys information for the named table. | `ConstraintFinderInterface` |
| [`getTableIndexes()`](#method-getTableIndexes) abstract | Obtains the indexes information for the named table. | `ConstraintFinderInterface` |
| [`getTablePrimaryKey()`](#method-getTablePrimaryKey) abstract | Obtains the primary key for the named table. | `ConstraintFinderInterface` |
| [`getTableUniques()`](#method-getTableUniques) abstract | Obtains the unique constraints information for the named table. | `ConstraintFinderInterface` |

## Method details

### getSchemaChecks() <span id="method-getSchemaChecks"></span>

```php
abstract public function getSchemaChecks(string $schema = '', bool $refresh = false): yii\db\CheckConstraint[][]
```

Returns check constraints for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |

**Returns**

[`CheckConstraint`](/docs/api/yii/db/checkconstraint/index.md)`[][]`: Check constraints for all tables in the database. Each array element is an array of [`CheckConstraint`](/docs/api/yii/db/checkconstraint/index.md) or its child classes.

### getSchemaDefaultValues() <span id="method-getSchemaDefaultValues"></span>

```php
abstract public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): yii\db\DefaultValueConstraint[]
```

Returns default value constraints for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |

**Returns**

[`DefaultValueConstraint`](/docs/api/yii/db/defaultvalueconstraint/index.md)`[]`: Default value constraints for all tables in the database. Each array element is an array of [`DefaultValueConstraint`](/docs/api/yii/db/defaultvalueconstraint/index.md) or its child classes.

### getSchemaForeignKeys() <span id="method-getSchemaForeignKeys"></span>

```php
abstract public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): yii\db\ForeignKeyConstraint[][]
```

Returns foreign keys for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |

**Returns**

[`ForeignKeyConstraint`](/docs/api/yii/db/foreignkeyconstraint/index.md)`[][]`: Foreign keys for all tables in the database. Each array element is an array of [`ForeignKeyConstraint`](/docs/api/yii/db/foreignkeyconstraint/index.md) or its child classes.

### getSchemaIndexes() <span id="method-getSchemaIndexes"></span>

```php
abstract public function getSchemaIndexes(string $schema = '', bool $refresh = false): yii\db\IndexConstraint[][]
```

Returns indexes for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |

**Returns**

[`IndexConstraint`](/docs/api/yii/db/indexconstraint/index.md)`[][]`: Indexes for all tables in the database. Each array element is an array of [`IndexConstraint`](/docs/api/yii/db/indexconstraint/index.md) or its child classes.

### getSchemaPrimaryKeys() <span id="method-getSchemaPrimaryKeys"></span>

```php
abstract public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): yii\db\Constraint[]
```

Returns primary keys for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is `false`, cached data may be returned if available. |

**Returns**

[`Constraint`](/docs/api/yii/db/constraint/index.md)`[]`: Primary keys for all tables in the database. Each array element is an instance of [`Constraint`](/docs/api/yii/db/constraint/index.md) or its child class.

### getSchemaUniques() <span id="method-getSchemaUniques"></span>

```php
abstract public function getSchemaUniques(string $schema = '', bool $refresh = false): yii\db\Constraint[][]
```

Returns unique constraints for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is false, cached data may be returned if available. |

**Returns**

[`Constraint`](/docs/api/yii/db/constraint/index.md)`[][]`: Unique constraints for all tables in the database. Each array element is an array of [`Constraint`](/docs/api/yii/db/constraint/index.md) or its child classes.

### getTableChecks() <span id="method-getTableChecks"></span>

```php
abstract public function getTableChecks(string $name, bool $refresh = false): yii\db\CheckConstraint[]
```

Obtains the check constraints information for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`CheckConstraint`](/docs/api/yii/db/checkconstraint/index.md)`[]`: Table check constraints.

### getTableDefaultValues() <span id="method-getTableDefaultValues"></span>

```php
abstract public function getTableDefaultValues(string $name, bool $refresh = false): yii\db\DefaultValueConstraint[]
```

Obtains the default value constraints information for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`DefaultValueConstraint`](/docs/api/yii/db/defaultvalueconstraint/index.md)`[]`: Table default value constraints.

### getTableForeignKeys() <span id="method-getTableForeignKeys"></span>

```php
abstract public function getTableForeignKeys(string $name, bool $refresh = false): yii\db\ForeignKeyConstraint[]
```

Obtains the foreign keys information for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`ForeignKeyConstraint`](/docs/api/yii/db/foreignkeyconstraint/index.md)`[]`: Table foreign keys.

### getTableIndexes() <span id="method-getTableIndexes"></span>

```php
abstract public function getTableIndexes(string $name, bool $refresh = false): yii\db\IndexConstraint[]
```

Obtains the indexes information for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`IndexConstraint`](/docs/api/yii/db/indexconstraint/index.md)`[]`: Table indexes.

### getTablePrimaryKey() <span id="method-getTablePrimaryKey"></span>

```php
abstract public function getTablePrimaryKey(string $name, bool $refresh = false): yii\db\Constraint|null
```

Obtains the primary key for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`Constraint`](/docs/api/yii/db/constraint/index.md)`|null`: Table primary key, `null` if the table has no primary key.

### getTableUniques() <span id="method-getTableUniques"></span>

```php
abstract public function getTableUniques(string $name, bool $refresh = false): yii\db\Constraint[]
```

Obtains the unique constraints information for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the information even if it is found in the cache. |

**Returns**

[`Constraint`](/docs/api/yii/db/constraint/index.md)`[]`: Table unique constraints.