# Schema

> Schema is the class for retrieving metadata from MS SQL Server databases (version 2019 and above).

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

| class | `yii\db\mssql\Schema` |
| --- | --- |
| Extends | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\db\ConstraintFinderInterface`](/docs/api/yii/db/constraintfinderinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Uses traits | [`yii\db\ViewFinderTrait`](/docs/api/yii/db/viewfindertrait/index.md), [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| Since | 2.0 |
| Source | [`framework/db/mssql/Schema.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/mssql/Schema.php#L45) |

Schema is the class for retrieving metadata from MS SQL Server databases (version 2019 and above).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-columnSchemaClass"></span>`$columnSchemaClass` | `class-string<yii\db\T>\|array{class?: class-string<yii\db\T>, __class?: class-string<yii\db\T>}` | Default: `\yii\db\mssql\ColumnSchema::class`. Available since 2.0.11. | `Schema` |
| <span id="property-db"></span>[`$db`](/docs/api/yii/db/schema/index.md#property-db) | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The database connection Default: `null`. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-defaultSchema"></span>`$defaultSchema` | `string` | The default schema used for the current session. Default: `'dbo'`. | `Schema` |
| <span id="property-exceptionMap"></span>[`$exceptionMap`](/docs/api/yii/db/schema/index.md#property-exceptionMap) | `array` | Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used. Default: `['SQLSTATE[23' => 'yii\db\IntegrityException']`. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-lastInsertID"></span>[`$lastInsertID`](/docs/api/yii/db/schema/index.md#property-lastInsertID) read-only | `string` | The row ID of the last row inserted, or the last value retrieved from the sequence object. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-queryBuilder"></span>[`$queryBuilder`](/docs/api/yii/db/schema/index.md#property-queryBuilder) read-only | `yii\db\TQueryBuilder` | The query builder for this connection. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-schemaChecks"></span>[`$schemaChecks`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaChecks) read-only | [`yii\db\CheckConstraint`](/docs/api/yii/db/checkconstraint/index.md)`[][]` | Check constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-schemaDefaultValues"></span>[`$schemaDefaultValues`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaDefaultValues) read-only | [`yii\db\DefaultValueConstraint`](/docs/api/yii/db/defaultvalueconstraint/index.md)`[]` | Default value constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-schemaForeignKeys"></span>[`$schemaForeignKeys`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaForeignKeys) read-only | [`yii\db\ForeignKeyConstraint`](/docs/api/yii/db/foreignkeyconstraint/index.md)`[][]` | Foreign keys for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-schemaIndexes"></span>[`$schemaIndexes`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaIndexes) read-only | [`yii\db\IndexConstraint`](/docs/api/yii/db/indexconstraint/index.md)`[][]` | Indexes for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-schemaNames"></span>[`$schemaNames`](/docs/api/yii/db/schema/index.md#property-schemaNames) read-only | `string[]` | All schema names in the database, except system schemas. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-schemaPrimaryKeys"></span>[`$schemaPrimaryKeys`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaPrimaryKeys) read-only | [`yii\db\Constraint`](/docs/api/yii/db/constraint/index.md)`[]` | Primary keys for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-schemaUniques"></span>[`$schemaUniques`](/docs/api/yii/db/constraintfindertrait/index.md#property-schemaUniques) read-only | [`yii\db\IndexConstraint`](/docs/api/yii/db/indexconstraint/index.md)`[][]` | Unique constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="property-serverVersion"></span>[`$serverVersion`](/docs/api/yii/db/schema/index.md#property-serverVersion) read-only | `string` | Server version as a string. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-systemSchemaNames"></span>`$systemSchemaNames` | `array` | Default: `['guest']`. | `Schema` |
| <span id="property-tableNames"></span>[`$tableNames`](/docs/api/yii/db/schema/index.md#property-tableNames) read-only | `string[]` | All table names in the database. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-tableSchemas"></span>[`$tableSchemas`](/docs/api/yii/db/schema/index.md#property-tableSchemas) read-only | [`yii\db\TableSchema`](/docs/api/yii/db/tableschema/index.md)`[]` | The metadata for all tables in the database. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-transactionIsolationLevel"></span>[`$transactionIsolationLevel`](/docs/api/yii/db/schema/index.md#property-transactionIsolationLevel) write-only | `string` | The transaction isolation level to use for this transaction. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="property-typeMap"></span>`$typeMap` | `array` | Mapping from physical column types (keys) to abstract column types (values). Default: `['bigint' => self::TYPE_BIGINT, 'numeric' => self::TYPE_DECIMAL, 'bit' => self::TYPE_SMALLINT, 'smallint' => self::TYPE_SMALLINT, 'decimal' => self::TYPE_DECIMAL, 'smallmoney' => self::TYPE_MONEY, 'int' => self::TYPE_INTEGER, 'tinyint' => self::TYPE_TINYINT, 'money' => self::TYPE_MONEY, 'float' => self::TYPE_FLOAT, 'double' => self::TYPE_DOUBLE, 'real' => self::TYPE_FLOAT, 'date' => self::TYPE_DATE, 'datetimeoffset' => self::TYPE_DATETIME, 'datetime2' => self::TYPE_DATETIME, 'smalldatetime' => self::TYPE_DATETIME, 'datetime' => self::TYPE_DATETIME, 'time' => self::TYPE_TIME, 'char' => self::TYPE_CHAR, 'varchar' => self::TYPE_STRING, 'text' => self::TYPE_TEXT, 'nchar' => self::TYPE_CHAR, 'nvarchar' => self::TYPE_STRING, 'ntext' => self::TYPE_TEXT, 'binary' => self::TYPE_BINARY, 'varbinary' => self::TYPE_BINARY, 'image' => self::TYPE_BINARY, 'timestamp' => self::TYPE_TIMESTAMP, 'hierarchyid' => self::TYPE_STRING, 'uniqueidentifier' => self::TYPE_STRING, 'sql_variant' => self::TYPE_STRING, 'xml' => self::TYPE_STRING, 'table' => self::TYPE_STRING]`. | `Schema` |
| <span id="property-viewNames"></span>`$viewNames` read-only | `string[]` | All view names in the database. | [`yii\db\ViewFinderTrait`](/docs/api/yii/db/viewfindertrait/index.md) |
| [`$columnQuoteCharacter`](#property-columnQuoteCharacter) protected | `string\|string[]` | Default: `['[', ']']`. Available since 2.0.14. | `Schema` |
| [`$tableQuoteCharacter`](#property-tableQuoteCharacter) protected | `string\|string[]` | Default: `['[', ']']`. Available since 2.0.14. | `Schema` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-convertException"></span>[`convertException()`](/docs/api/yii/db/schema/index.md#method-convertException) | Converts a DB exception to a more concrete one if possible. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`createColumnSchemaBuilder()`](#method-createColumnSchemaBuilder) | Create a column schema builder instance giving the type and value precision. | `Schema` |
| [`createQueryBuilder()`](#method-createQueryBuilder) | Creates a query builder for the MSSQL database. | `Schema` |
| [`createSavepoint()`](#method-createSavepoint) | Creates a new savepoint. | `Schema` |
| [`findUniqueIndexes()`](#method-findUniqueIndexes) | Returns all unique indexes for the given table. | `Schema` |
| <span id="method-getLastInsertID"></span>[`getLastInsertID()`](/docs/api/yii/db/schema/index.md#method-getLastInsertID) | Returns the ID of the last inserted row or sequence value. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getPdoType"></span>[`getPdoType()`](/docs/api/yii/db/schema/index.md#method-getPdoType) | Determines the PDO type for the given PHP data value. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getQueryBuilder"></span>[`getQueryBuilder()`](/docs/api/yii/db/schema/index.md#method-getQueryBuilder) |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getRawTableName"></span>[`getRawTableName()`](/docs/api/yii/db/schema/index.md#method-getRawTableName) | Returns the actual name of a given table name. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getSchemaChecks"></span>[`getSchemaChecks()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaChecks) | Returns check constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getSchemaDefaultValues"></span>[`getSchemaDefaultValues()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaDefaultValues) | Returns default value constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getSchemaForeignKeys"></span>[`getSchemaForeignKeys()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaForeignKeys) | Returns foreign keys for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getSchemaIndexes"></span>[`getSchemaIndexes()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaIndexes) | Returns indexes for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getSchemaNames"></span>[`getSchemaNames()`](/docs/api/yii/db/schema/index.md#method-getSchemaNames) | Returns all schema names in the database, except system schemas. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getSchemaPrimaryKeys"></span>[`getSchemaPrimaryKeys()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaPrimaryKeys) | Returns primary keys for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getSchemaUniques"></span>[`getSchemaUniques()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getSchemaUniques) | Returns unique constraints for all tables in the database. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getServerVersion"></span>[`getServerVersion()`](/docs/api/yii/db/schema/index.md#method-getServerVersion) | Returns a server version as a string comparable by [`version_compare()`](https://www.php.net/manual/en/function.version-compare.php). | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getTableChecks"></span>[`getTableChecks()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTableChecks) | Obtains the check constraints information for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getTableDefaultValues"></span>[`getTableDefaultValues()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTableDefaultValues) | Obtains the default value constraints information for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getTableForeignKeys"></span>[`getTableForeignKeys()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTableForeignKeys) | Obtains the foreign keys information for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getTableIndexes"></span>[`getTableIndexes()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTableIndexes) | Obtains the indexes information for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getTableNames"></span>[`getTableNames()`](/docs/api/yii/db/schema/index.md#method-getTableNames) | Returns all table names in the database. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getTablePrimaryKey"></span>[`getTablePrimaryKey()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTablePrimaryKey) | Obtains the primary key for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getTableSchema"></span>[`getTableSchema()`](/docs/api/yii/db/schema/index.md#method-getTableSchema) | Obtains the metadata for the named table. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getTableSchemas"></span>[`getTableSchemas()`](/docs/api/yii/db/schema/index.md#method-getTableSchemas) | Returns the metadata for all tables in the database. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getTableUniques"></span>[`getTableUniques()`](/docs/api/yii/db/constraintfindertrait/index.md#method-getTableUniques) | Obtains the unique constraints information for the named table. | [`yii\db\ConstraintFinderTrait`](/docs/api/yii/db/constraintfindertrait/index.md) |
| <span id="method-getViewNames"></span>[`getViewNames()`](/docs/api/yii/db/viewfindertrait/index.md#method-getViewNames) | Returns all view names in the database. | [`yii\db\ViewFinderTrait`](/docs/api/yii/db/viewfindertrait/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`insert()`](#method-insert) | Executes the INSERT command, returning primary key values. | `Schema` |
| <span id="method-isReadQuery"></span>[`isReadQuery()`](/docs/api/yii/db/schema/index.md#method-isReadQuery) | Returns a value indicating whether a SQL statement is for read purpose. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`quoteColumnName()`](#method-quoteColumnName) | Quotes a column name for use in a query. | `Schema` |
| <span id="method-quoteSimpleColumnName"></span>[`quoteSimpleColumnName()`](/docs/api/yii/db/schema/index.md#method-quoteSimpleColumnName) | Quotes a simple column name for use in a query. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-quoteSimpleTableName"></span>[`quoteSimpleTableName()`](/docs/api/yii/db/schema/index.md#method-quoteSimpleTableName) | Quotes a simple table name for use in a query. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`quoteSystemCatalogName()`](#method-quoteSystemCatalogName) | Quotes the `[sys]` system catalog name, optionally qualified by the database catalog. | `Schema` |
| [`quoteTableName()`](#method-quoteTableName) | Qualifies single-part table names with [`$defaultSchema`](/docs/api/yii/db/mssql/schema/index.md#property-defaultSchema) when it differs from `'dbo'`, ensuring unqualified DDL and DML statements target the configured schema rather than the SQL Server login default. | `Schema` |
| <span id="method-quoteValue"></span>[`quoteValue()`](/docs/api/yii/db/schema/index.md#method-quoteValue) | Quotes a string value for use in a query. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-refresh"></span>[`refresh()`](/docs/api/yii/db/schema/index.md#method-refresh) | Refreshes the schema. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-refreshTableSchema"></span>[`refreshTableSchema()`](/docs/api/yii/db/schema/index.md#method-refreshTableSchema) | Refreshes the particular table schema. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`releaseSavepoint()`](#method-releaseSavepoint) | Releases an existing savepoint. | `Schema` |
| [`resolveRawCatalogSchemaName()`](#method-resolveRawCatalogSchemaName) | Resolves a schema argument into optional catalog and schema names without loading database metadata. | `Schema` |
| <span id="method-resolveRawTableName"></span>[`resolveRawTableName()`](/docs/api/yii/db/schema/index.md#method-resolveRawTableName) | Resolves the table name and schema name (if any) without loading database metadata. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`rollBackSavepoint()`](#method-rollBackSavepoint) | Rolls back to a previously created savepoint. | `Schema` |
| <span id="method-setTransactionIsolationLevel"></span>[`setTransactionIsolationLevel()`](/docs/api/yii/db/schema/index.md#method-setTransactionIsolationLevel) | Sets the isolation level of the current transaction. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-supportsSavepoint"></span>[`supportsSavepoint()`](/docs/api/yii/db/schema/index.md#method-supportsSavepoint) |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-unquoteSimpleColumnName"></span>[`unquoteSimpleColumnName()`](/docs/api/yii/db/schema/index.md#method-unquoteSimpleColumnName) | Unquotes a simple column name. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-unquoteSimpleTableName"></span>[`unquoteSimpleTableName()`](/docs/api/yii/db/schema/index.md#method-unquoteSimpleTableName) | Unquotes a simple table name. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-createColumnSchema"></span>[`createColumnSchema()`](/docs/api/yii/db/schema/index.md#method-createColumnSchema) protected | Creates a column schema for the database. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`findColumns()`](#method-findColumns) protected | Collects the metadata of table columns. | `Schema` |
| [`findForeignKeys()`](#method-findForeignKeys) protected | Collects the foreign key column details for the given table. | `Schema` |
| [`findPrimaryKeys()`](#method-findPrimaryKeys) protected | Collects the primary key column details for the given table. | `Schema` |
| [`findSchemaNames()`](#method-findSchemaNames) protected | Returns all schema names in the database, including the default one but not system schemas. | `Schema` |
| [`findTableConstraints()`](#method-findTableConstraints) protected | Collects the constraint details for the given table and constraint type. | `Schema` |
| [`findTableNames()`](#method-findTableNames) protected | Returns all table names in the database. | `Schema` |
| [`findViewNames()`](#method-findViewNames) protected |  | `Schema` |
| <span id="method-getCacheKey"></span>[`getCacheKey()`](/docs/api/yii/db/schema/index.md#method-getCacheKey) protected | Returns the cache key for the specified table name. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getCacheTag"></span>[`getCacheTag()`](/docs/api/yii/db/schema/index.md#method-getCacheTag) protected | Returns the cache tag name. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="method-getColumnPhpType"></span>[`getColumnPhpType()`](/docs/api/yii/db/schema/index.md#method-getColumnPhpType) protected | Extracts the PHP type from abstract DB type. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`getSchemaMetadata()`](#method-getSchemaMetadata) protected | Returns the metadata of the given type for all tables in the given schema. | `Schema` |
| <span id="method-getTableMetadata"></span>[`getTableMetadata()`](/docs/api/yii/db/schema/index.md#method-getTableMetadata) protected | Returns the metadata of the given type for the given table. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`getTableNameParts()`](#method-getTableNameParts) protected | Splits full table name into parts. | `Schema` |
| [`loadColumnSchema()`](#method-loadColumnSchema) protected | Loads the column information into a [`ColumnSchema`](/docs/api/yii/db/mssql/columnschema/index.md) object. | `Schema` |
| [`loadTableChecks()`](#method-loadTableChecks) protected |  | `Schema` |
| [`loadTableDefaultValues()`](#method-loadTableDefaultValues) protected |  | `Schema` |
| [`loadTableForeignKeys()`](#method-loadTableForeignKeys) protected |  | `Schema` |
| [`loadTableIndexes()`](#method-loadTableIndexes) protected |  | `Schema` |
| [`loadTablePrimaryKey()`](#method-loadTablePrimaryKey) protected |  | `Schema` |
| [`loadTableSchema()`](#method-loadTableSchema) protected | Loads the metadata for the specified table. | `Schema` |
| [`loadTableUniques()`](#method-loadTableUniques) protected |  | `Schema` |
| <span id="method-normalizePdoRowKeyCase"></span>[`normalizePdoRowKeyCase()`](/docs/api/yii/db/schema/index.md#method-normalizePdoRowKeyCase) protected | Changes row's array key case to lower if PDO's one is set to uppercase. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| [`resolveTableName()`](#method-resolveTableName) protected | Resolves the table name and schema name (if any). | `Schema` |
| <span id="method-setTableMetadata"></span>[`setTableMetadata()`](/docs/api/yii/db/schema/index.md#method-setTableMetadata) protected | Sets the metadata of the given type for the given table. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-TYPE_PK"></span>[`TYPE_PK`](/docs/api/yii/db/schema/index.md#const-TYPE_PK) | `'pk'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_UPK"></span>[`TYPE_UPK`](/docs/api/yii/db/schema/index.md#const-TYPE_UPK) | `'upk'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_BIGPK"></span>[`TYPE_BIGPK`](/docs/api/yii/db/schema/index.md#const-TYPE_BIGPK) | `'bigpk'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_UBIGPK"></span>[`TYPE_UBIGPK`](/docs/api/yii/db/schema/index.md#const-TYPE_UBIGPK) | `'ubigpk'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_CHAR"></span>[`TYPE_CHAR`](/docs/api/yii/db/schema/index.md#const-TYPE_CHAR) | `'char'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_STRING"></span>[`TYPE_STRING`](/docs/api/yii/db/schema/index.md#const-TYPE_STRING) | `'string'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_TEXT"></span>[`TYPE_TEXT`](/docs/api/yii/db/schema/index.md#const-TYPE_TEXT) | `'text'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_TINYINT"></span>[`TYPE_TINYINT`](/docs/api/yii/db/schema/index.md#const-TYPE_TINYINT) | `'tinyint'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_SMALLINT"></span>[`TYPE_SMALLINT`](/docs/api/yii/db/schema/index.md#const-TYPE_SMALLINT) | `'smallint'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_INTEGER"></span>[`TYPE_INTEGER`](/docs/api/yii/db/schema/index.md#const-TYPE_INTEGER) | `'integer'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_BIGINT"></span>[`TYPE_BIGINT`](/docs/api/yii/db/schema/index.md#const-TYPE_BIGINT) | `'bigint'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_FLOAT"></span>[`TYPE_FLOAT`](/docs/api/yii/db/schema/index.md#const-TYPE_FLOAT) | `'float'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_DOUBLE"></span>[`TYPE_DOUBLE`](/docs/api/yii/db/schema/index.md#const-TYPE_DOUBLE) | `'double'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_DECIMAL"></span>[`TYPE_DECIMAL`](/docs/api/yii/db/schema/index.md#const-TYPE_DECIMAL) | `'decimal'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_DATETIME"></span>[`TYPE_DATETIME`](/docs/api/yii/db/schema/index.md#const-TYPE_DATETIME) | `'datetime'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_TIMESTAMP"></span>[`TYPE_TIMESTAMP`](/docs/api/yii/db/schema/index.md#const-TYPE_TIMESTAMP) | `'timestamp'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_TIME"></span>[`TYPE_TIME`](/docs/api/yii/db/schema/index.md#const-TYPE_TIME) | `'time'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_DATE"></span>[`TYPE_DATE`](/docs/api/yii/db/schema/index.md#const-TYPE_DATE) | `'date'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_BINARY"></span>[`TYPE_BINARY`](/docs/api/yii/db/schema/index.md#const-TYPE_BINARY) | `'binary'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_BOOLEAN"></span>[`TYPE_BOOLEAN`](/docs/api/yii/db/schema/index.md#const-TYPE_BOOLEAN) | `'boolean'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_MONEY"></span>[`TYPE_MONEY`](/docs/api/yii/db/schema/index.md#const-TYPE_MONEY) | `'money'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-TYPE_JSON"></span>[`TYPE_JSON`](/docs/api/yii/db/schema/index.md#const-TYPE_JSON) | `'json'` |  | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |
| <span id="const-SCHEMA_CACHE_VERSION"></span>[`SCHEMA_CACHE_VERSION`](/docs/api/yii/db/schema/index.md#const-SCHEMA_CACHE_VERSION) | `1` | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. | [`yii\db\Schema`](/docs/api/yii/db/schema/index.md) |

## Property details

### $columnQuoteCharacter <span id="property-columnQuoteCharacter"></span>

```php
protected string|string[] $columnQuoteCharacter = ['[', ']']
```

An array of 2 characters can be used in case starting and ending characters are different.

**Since**

2.0.14

### $tableQuoteCharacter <span id="property-tableQuoteCharacter"></span>

```php
protected string|string[] $tableQuoteCharacter = ['[', ']']
```

An array of 2 characters can be used in case starting and ending characters are different.

**Since**

2.0.14

## Method details

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

```php
public function createColumnSchemaBuilder(mixed $type, mixed $length = null): yii\db\ColumnSchemaBuilder
```

Create a column schema builder instance giving the type and value precision.

This method may be overridden by child classes to create a DBMS-specific column schema builder.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `mixed` | Type of the column. See [`ColumnSchemaBuilder::$type`](/docs/api/yii/db/columnschemabuilder/index.md#property-type). |
| `$length` | `mixed` | Length or precision of the column. See [`ColumnSchemaBuilder::$length`](/docs/api/yii/db/columnschemabuilder/index.md#property-length). |

**Returns**

[`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md): Column schema builder instance

**Since**

2.0.6

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

```php
public function createQueryBuilder(): yii\db\mssql\QueryBuilder
```

Creates a query builder for the MSSQL database.

**Returns**

[`QueryBuilder`](/docs/api/yii/db/mssql/querybuilder/index.md): Query builder interface.

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

```php
public function createSavepoint(mixed $name): mixed
```

Creates a new savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The savepoint name |

**Returns**

`mixed`

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

```php
public function findUniqueIndexes(yii\db\mssql\TableSchema $table): array
```

Returns all unique indexes for the given table.

Each array element is of the following structure:

```
[
    'IndexName1' => ['col1' [, ...]],
    'IndexName2' => ['col2' [, ...]],
]
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md) | The table metadata. |

**Returns**

`array`: All unique indexes for the given table.

**Since**

2.0.4

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

```php
public function insert(mixed $table, mixed $columns): array|false
```

Executes the INSERT command, returning primary key values.

Retrieves the inserted row via the `OUTPUT INSERTED.*` block emitted by `\yii\db\mssql\QueryBuilder::insert()` so
that `IDENTITY` values, computed columns, and `uniqueidentifier` defaults are returned to the caller.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table that new rows will be inserted into. |
| `$columns` | `mixed` | The column data (name => value) to be inserted into the table. |

**Returns**

`array|false`: Primary key values or false if the command fails

**Since**

2.0.4

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

```php
public function quoteColumnName(mixed $name): string
```

Quotes a column name for use in a query.

If the column name contains prefix, the prefix will also be properly quoted.
If the column name is already fully enclosed in the quote characters, or contains '(', '[[' or '{{', then this
method will do nothing.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | Column name. |

**Returns**

`string`: The properly quoted column name.

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

```php
public function quoteSystemCatalogName(string|null $catalogName): string
```

Quotes the `[sys]` system catalog name, optionally qualified by the database catalog.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$catalogName` | `string\|null` | The database catalog name, or `null` to target the current database. |

**Returns**

`string`: The `[sys]` schema name, prefixed with the quoted catalog when one is provided.

**Since**

22.0

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

```php
public function quoteTableName(mixed $name): mixed
```

Qualifies single-part table names with [`$defaultSchema`](/docs/api/yii/db/mssql/schema/index.md#property-defaultSchema) when it differs from `'dbo'`, ensuring
unqualified DDL and DML statements target the configured schema rather than the SQL Server login default.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` |  |

**Returns**

`mixed`

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

```php
public function releaseSavepoint(mixed $name): mixed
```

Releases an existing savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The savepoint name |

**Returns**

`mixed`

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

```php
public function resolveRawCatalogSchemaName(string $schema): array{string|null, string}
```

Resolves a schema argument into optional catalog and schema names without loading database metadata.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema argument. |

**Returns**

`array{string|null, string}`: The catalog and schema names.

**Since**

22.0

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

```php
public function rollBackSavepoint(mixed $name): mixed
```

Rolls back to a previously created savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The savepoint name |

**Returns**

`mixed`

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

```php
protected function findColumns(yii\db\mssql\TableSchema $table): bool
```

Collects the metadata of table columns.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md) | The table metadata. |

**Returns**

`bool`: Whether the table exists in the database.

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

```php
protected function findForeignKeys(yii\db\mssql\TableSchema $table): mixed
```

Collects the foreign key column details for the given table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md) | The table metadata |

**Returns**

`mixed`

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

```php
protected function findPrimaryKeys(yii\db\mssql\TableSchema $table): mixed
```

Collects the primary key column details for the given table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md) | The table metadata |

**Returns**

`mixed`

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

```php
protected function findSchemaNames(): array
```

Returns all schema names in the database, including the default one but not system schemas.

This method should be overridden by child classes in order to support this feature
because the default implementation simply throws an exception.

**Returns**

`array`: All schema names in the database, except system schemas.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

**Since**

2.0.4

**See also**

- <https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-database-principals-transact-sql>

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

```php
protected function findTableConstraints(yii\db\mssql\TableSchema $table, string $type): array
```

Collects the constraint details for the given table and constraint type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md) | The table metadata. |
| `$type` | `string` | Either `PK` or `UQ`. |

**Returns**

`array`: Each entry contains index_name and field_name.

**Since**

2.0.4

**See also**

- <https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-key-constraints-transact-sql>

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

```php
protected function findTableNames(mixed $schema = ''): array
```

Returns all table names in the database.

This method should be overridden by child classes in order to support this feature
because the default implementation simply throws an exception.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `mixed` | The schema of the tables. Defaults to empty string, meaning the current or default schema. |

**Returns**

`array`: All table names in the database. The names have NO schema name prefix.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

**See also**

- <https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-objects-transact-sql>

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

```php
protected function findViewNames(mixed $schema = '')
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `mixed` |  |

**See also**

- <https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-views-transact-sql>

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

```php
protected function getSchemaMetadata(mixed $schema, mixed $type, mixed $refresh): array
```

Returns the metadata of the given type for all tables in the given schema.

This method will call a `'getTable' . ucfirst($type)` named method with the table name
and the refresh flag to obtain the metadata.

**Parameters**

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

**Returns**

`array`: Array of metadata.

**Since**

2.0.13

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

```php
protected function getTableNameParts(mixed $name): array
```

Splits full table name into parts.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | Full table name. |

**Returns**

`array`: Table name parts.

**Since**

2.0.22

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

```php
protected function loadColumnSchema(array $info): yii\db\mssql\T
```

Loads the column information into a [`ColumnSchema`](/docs/api/yii/db/mssql/columnschema/index.md) object.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$info` | `array` | Column information. |

**Returns**

`yii\db\mssql\T`: The column schema object.

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

```php
protected function loadTableChecks(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function loadTableDefaultValues(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function loadTableForeignKeys(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function loadTableIndexes(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function loadTablePrimaryKey(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function loadTableSchema(mixed $name): yii\db\TableSchema|null
```

Loads the metadata for the specified table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | Table name |

**Returns**

[`yii\db\TableSchema`](/docs/api/yii/db/tableschema/index.md)`|null`: DBMS-dependent table metadata, `null` if the table does not exist.

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

```php
protected function loadTableUniques(mixed $tableName)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `mixed` |  |

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

```php
protected function resolveTableName(string $name): yii\db\mssql\TableSchema
```

Resolves the table name and schema name (if any).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The table name |

**Returns**

[`TableSchema`](/docs/api/yii/db/mssql/tableschema/index.md): Resolved table, schema, etc. names.