Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/relational-databases/databases/database-identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ CREATE TABLE TableX (

This table also has an unnamed constraint. The `PRIMARY KEY` constraint has no identifier.

Some identifiers, such as constraint names and other schema-scoped objects, must be unique within a database schema. For example, two primary key constraints in the same schema can't share a name, so the second table creation statement isn't allowed:

```sql
USE AdventureWorks2022;
GO

CREATE TABLE [SalesOrderGeneral Table] (
[Order] INT NOT NULL,
[SalesOrderID] INT IDENTITY(1, 1) NOT NULL,
[SalesOrderDetailID] INT NOT NULL,
[ModifiedDate] DATETIME NOT NULL,
CONSTRAINT [PK_SalesOrder] PRIMARY KEY CLUSTERED (
[Order] ASC,
[SalesOrderID] ASC
)
);
GO

-- Primary key identifier conflicts with existing primary key, and so will result in an error.
CREATE TABLE [SalesOrderDetail Table] (
[Order] INT NOT NULL,
[SalesOrderDetailID] INT IDENTITY(1, 1) NOT NULL,
[OrderQty] SMALLINT NOT NULL,
[ProductID] INT NOT NULL,
[UnitPrice] MONEY NOT NULL,
[UnitPriceDiscount] MONEY NOT NULL,
[ModifiedDate] DATETIME NOT NULL,
CONSTRAINT [PK_SalesOrder] PRIMARY KEY CLUSTERED (
[Order] ASC,
[SalesOrderDetailID] ASC
)
);
GO
```

However, each table can contain its own column named `Order`, because column names only need to be unique within each table, not within the schema.

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.

> [!NOTE]
Expand Down