Skip to content

Commit b175c14

Browse files
20260330 database identifiers edit pass
1 parent 44801ec commit b175c14

1 file changed

Lines changed: 20 additions & 31 deletions

File tree

docs/relational-databases/databases/database-identifiers.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >
2626

2727
[!INCLUDE [SQL Server Azure SQL Database Synapse Analytics PDW FabricSE FabricDW FabricSQLDB](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb.md)]
2828

29-
The database object name is referred to as its identifier. Everything in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] can have an identifier. Servers, databases, and database objects, such as tables, views, columns, indexes, triggers, procedures, constraints, and rules, can have identifiers. Identifiers are required for most objects, but are optional for some objects such as constraints.
29+
The database object name is referred to as its identifier.
3030

31-
An object identifier is created when the object is defined. The identifier is then used to reference the object. For example, the following statement creates a table with the identifier `TableX`, and two columns with the identifiers `KeyCol` and `Description`:
31+
Servers, databases, and database objects, such as tables, views, columns, indexes, triggers, procedures, constraints, and rules, can have identifiers. Most objects require identifiers, but some objects, such as constraints, make them optional.
32+
33+
You create an object identifier when you define the object. Use the identifier to reference the object. For example, the following statement creates a table with the identifier `TableX`, and two columns with the identifiers `KeyCol` and `Description`:
3234

3335
```sql
3436
CREATE TABLE TableX (
@@ -37,11 +39,14 @@ CREATE TABLE TableX (
3739
);
3840
```
3941

40-
This table also has an unnamed constraint. The `PRIMARY KEY` constraint has no identifier.
42+
This table also has an unnamed constraint. The primary key constraint has no identifier, and so would be assigned a system-generated name like `PK__TableX__D7CB9CCCEEF0806C`, which you could observe in system metadata views like `sys.key_constraints`.
43+
44+
Constraint names and other schema-scoped objects must be unique within a database schema. For example, two primary key constraints can't share a name. However, column names only need to be unique within each table, not within the schema.
4145

42-
Some identifiers, such as constraint names and other schema-scoped objects, must be unique within a database schema. For example, two primary key constraints can't share a name. However, column names only need to be unique within each table, not within the schema.
46+
The collation of an identifier depends on the level at which you define it.
4347

44-
The collation of an identifier depends on the level at which it's defined. Identifiers of instance-level objects, such as logins and database names, are assigned the default collation of the instance. Identifiers of objects in a database, such as tables, views, and column names, are assigned the default collation of the database. For example, two tables with names that differ only in case can be created in a database that has case-sensitive collation, but can't be created in a database that has case-insensitive collation.
48+
- The default collation of the instance is assigned to identifiers of instance-level objects, such as logins and database names.
49+
- The default collation of the database is assigned to identifiers of objects in a database, such as tables, views, and column names. For example, you can create two tables with names that differ only in case in a database that has case-sensitive collation, but you can't create them in a database that has case-insensitive collation.
4550

4651
> [!NOTE]
4752
> The names of variables, or the parameters of functions and stored procedures must comply with the rules for [!INCLUDE [tsql](../../includes/tsql-md.md)] identifiers.
@@ -103,17 +108,17 @@ Both regular and delimited identifiers must contain from 1 through 128 character
103108

104109
## Rules for regular identifiers
105110

106-
The names of variables, functions, and stored procedures must comply with the following rules for [!INCLUDE [tsql](../../includes/tsql-md.md)] identifiers.
111+
The names of variables, functions, and stored procedures must follow these rules for [!INCLUDE [tsql](../../includes/tsql-md.md)] identifiers.
107112

108-
1. The first character must be one of the following items:
113+
1. The first character must be one of the following characters:
109114

110115
- A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from `a` through `z`, from `A` through `Z`, and also letter characters from other languages.
111116

112117
- The underscore (`_`), at sign (`@`), or number sign (`#`).
113118

114119
Certain symbols at the beginning of an identifier have special meaning in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. A regular identifier that starts with the at sign always denotes a local variable or parameter and can't be used as the name of any other type of object. An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (`##`) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we don't recommend this practice.
115120

116-
Some [!INCLUDE [tsql](../../includes/tsql-md.md)] functions have names that start with double at signs (`@@`). To avoid confusion with these functions, you shouldn't use names that start with `@@`.
121+
Some [!INCLUDE [tsql](../../includes/tsql-md.md)] functions have names that start with double at signs (`@@`). To avoid confusion with these functions, don't use names that start with `@@`.
117122

118123
1. Subsequent characters can include the following list:
119124

@@ -123,42 +128,26 @@ The names of variables, functions, and stored procedures must comply with the fo
123128

124129
- The at sign (`@`), dollar sign (`$`), number sign (`#`), or underscore (`_`).
125130

126-
1. The identifier must not be a [!INCLUDE [tsql](../../includes/tsql-md.md)] reserved word. [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] reserves both the uppercase and lowercase versions of reserved words. When identifiers are used in [!INCLUDE [tsql](../../includes/tsql-md.md)] statements, the identifiers that don't comply with these rules must be delimited by double quotation marks or brackets. The words that are reserved depend on the database compatibility level. This level can be set by using the [ALTER DATABASE compatibility level](../../t-sql/statements/alter-database-transact-sql-compatibility-level.md) statement.
131+
1. The identifier must not be a [!INCLUDE [tsql](../../includes/tsql-md.md)] reserved word. [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] reserves both the uppercase and lowercase versions of reserved words. When you use identifiers in [!INCLUDE [tsql](../../includes/tsql-md.md)] statements, delimit identifiers that don't comply with these rules by using double quotation marks or brackets. The words that are reserved depend on the database compatibility level. Set the database compatibility level by using the [ALTER DATABASE compatibility level](../../t-sql/statements/alter-database-transact-sql-compatibility-level.md) statement.
127132

128-
1. Embedded spaces or special characters aren't allowed.
133+
1. Don't use embedded spaces or special characters.
129134

130-
1. [Supplementary characters](../collations/collation-and-unicode-support.md#Supplementary_Characters) aren't allowed.
135+
1. Don't use [Supplementary characters](../collations/collation-and-unicode-support.md#Supplementary_Characters).
131136

132-
When identifiers are used in [!INCLUDE [tsql](../../includes/tsql-md.md)] statements, the identifiers that don't comply with these rules must be delimited by double quotation marks or brackets.
137+
When you use identifiers in [!INCLUDE [tsql](../../includes/tsql-md.md)] statements, delimit identifiers that don't comply with these rules by using double quotation marks or brackets.
133138

134-
> [!NOTE]
135-
> Some rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using [ALTER DATABASE compatibility level](../../t-sql/statements/alter-database-transact-sql-compatibility-level.md).
139+
Some rules for the format of regular identifiers depend on the database compatibility level.
136140

137141
## Catalog collation in Azure SQL Database
138142

139-
You can't change or set the logical server collation on Azure SQL Database. However, you can configure each database's collations separately for data in the database and for catalog. The catalog collation determines the collation for system metadata, such as object identifiers. Both collations can be specified independently when you [create the database in the Azure portal](/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&preserve-view=true&tabs=azure-portal#create-a-single-database), in T-SQL with [CREATE DATABASE](../../t-sql/statements/create-database-transact-sql.md?view=azuresqldb-current&preserve-view=true#collation_name), in PowerShell with [New-AzSqlDatabase](/powershell/module/az.sql/new-azsqldatabase).
143+
You can't change or set the logical server collation on Azure SQL Database. However, you can configure each database's collations separately for data in the database and for catalog. The catalog collation determines the collation for system metadata, such as object identifiers. You can specify both collations independently when you [create the database in the Azure portal](/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&preserve-view=true&tabs=azure-portal#create-a-single-database), in T-SQL with [CREATE DATABASE](../../t-sql/statements/create-database-transact-sql.md?view=azuresqldb-current&preserve-view=true#collation_name), or in PowerShell with [New-AzSqlDatabase](/powershell/module/az.sql/new-azsqldatabase).
140144

141145
For details and examples, see [CREATE DATABASE](../../t-sql/statements/create-database-transact-sql.md?view=azuresqldb-current&preserve-view=true#collation_name). Specify a collation for the database (`COLLATE`) and a catalog collation for system metadata and object identifiers (`CATALOG_COLLATION`).
142146

143147
## Catalog collation in SQL database in Microsoft Fabric
144148

145-
You can't change or set the logical server collation on SQL database in Fabric.
146-
147-
Currently, by default the collation of a SQL database in Fabric is `SQL_Latin1_General_CP1_CI_AS` and can't be updated. Collations on individual columns are supported.
149+
Currently, by default the collation of a SQL database in Fabric is `SQL_Latin1_General_CP1_CI_AS`, but this can be configured when deploying. The collation can't be updated after deployment. Collations on individual columns are supported. For more information on deployment options, see [Options to create a SQL database in Fabric](/fabric/database/sql/create-options).
148150

149151
## Related content
150152

151-
- [ALTER TABLE (Transact-SQL)](../../t-sql/statements/alter-table-transact-sql.md)
152-
- [CREATE DATABASE](../../t-sql/statements/create-database-transact-sql.md)
153-
- [CREATE DEFAULT (Transact-SQL)](../../t-sql/statements/create-default-transact-sql.md)
154-
- [CREATE PROCEDURE (Transact-SQL)](../../t-sql/statements/create-procedure-transact-sql.md)
155-
- [CREATE RULE (Transact-SQL)](../../t-sql/statements/create-rule-transact-sql.md)
156-
- [CREATE TABLE (Transact-SQL)](../../t-sql/statements/create-table-transact-sql.md)
157-
- [CREATE TRIGGER (Transact-SQL)](../../t-sql/statements/create-trigger-transact-sql.md)
158-
- [CREATE VIEW (Transact-SQL)](../../t-sql/statements/create-view-transact-sql.md)
159-
- [DECLARE @local_variable (Transact-SQL)](../../t-sql/language-elements/declare-local-variable-transact-sql.md)
160-
- [DELETE (Transact-SQL)](../../t-sql/statements/delete-transact-sql.md)
161-
- [INSERT (Transact-SQL)](../../t-sql/statements/insert-transact-sql.md)
162153
- [Reserved Keywords (Transact-SQL)](../../t-sql/language-elements/reserved-keywords-transact-sql.md)
163-
- [SELECT (Transact-SQL)](../../t-sql/queries/select-transact-sql.md)
164-
- [UPDATE (Transact-SQL)](../../t-sql/queries/update-transact-sql.md)

0 commit comments

Comments
 (0)