Skip to content

Commit 77b117c

Browse files
authored
Merge pull request #35192 from MikeRayMSFT/250902-freshness
September 2025 - Freshness
2 parents 9bc4399 + 79f92c4 commit 77b117c

16 files changed

Lines changed: 792 additions & 669 deletions

docs/database-engine/database-mirroring/database-mirroring-sql-server.md

Lines changed: 364 additions & 317 deletions
Large diffs are not rendered by default.
Binary file not shown.
9.83 KB
Loading
Binary file not shown.
9.53 KB
Loading
Binary file not shown.
14.9 KB
Loading

docs/relational-databases/indexes/create-clustered-indexes.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
2-
title: "Create a clustered index"
2+
title: "Create a Clustered Index"
33
description: Create a clustered index in SQL Server and Azure SQL.
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.reviewer: mikeray
7-
ms.date: 01/12/2024
6+
ms.date: 09/02/2025
87
ms.service: sql
98
ms.subservice: table-view-index
109
ms.topic: how-to
@@ -22,20 +21,21 @@ monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-20
2221

2322
[!INCLUDE [SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB](../../includes/applies-to-version/sql-asdb-asdbmi-fabricsqldb.md)]
2423

25-
2624
You can create clustered indexes on tables by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)]. With few exceptions, every table should have a clustered index. Besides improving query performance, a clustered index can be rebuilt or reorganized on demand to control table fragmentation. A clustered index can also be created on a view. (Clustered indexes are defined in the article [Clustered and nonclustered indexes](clustered-and-nonclustered-indexes-described.md).)
2725

28-
## <a name="Implementations"></a> Typical implementations
26+
<a id="Implementations"></a>
27+
28+
## Typical implementations
2929

3030
Clustered indexes are implemented in the following ways:
3131

32-
- **PRIMARY KEY and UNIQUE constraints**
32+
- `PRIMARY KEY` and `UNIQUE` constraints**
3333

3434
When you create a `PRIMARY KEY` constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table doesn't already exist and you don't specify a unique nonclustered index. The primary key column can't allow `NULL` values.
3535

3636
When you create a `UNIQUE` constraint, a unique nonclustered index is created to enforce a `UNIQUE` constraint by default. You can specify a unique clustered index if a clustered index on the table doesn't already exist.
3737

38-
An index created as part of the constraint is automatically given the same name as the constraint name. For more information, see [Primary and Foreign Key Constraints](../tables/primary-and-foreign-key-constraints.md) and [Unique constraints and check constraints](../tables/unique-constraints-and-check-constraints.md).
38+
An index created as part of the constraint is automatically given the same name as the constraint name. For more information, see [Primary and foreign key constraints](../tables/primary-and-foreign-key-constraints.md) and [Unique constraints and check constraints](../tables/unique-constraints-and-check-constraints.md).
3939

4040
- **Index independent of a constraint**
4141

@@ -47,7 +47,7 @@ Clustered indexes are implemented in the following ways:
4747

4848
- If a clustered index is created on a heap with several existing nonclustered indexes, all the nonclustered indexes must be rebuilt so that they contain the clustering key value instead of the row identifier (RID). Similarly, if a clustered index is dropped on a table that has several nonclustered indexes, the nonclustered indexes are all rebuilt as part of the `DROP` operation. This process might take significant time on large tables.
4949

50-
The preferred way to build indexes on large tables is to start with the clustered index and then build any nonclustered indexes. Consider setting the `ONLINE` option to ON when you create indexes on existing tables. When set to ON, long-term table locks aren't held. This enables queries or updates to the underlying table to continue. For more information, see [Perform Index Operations Online](perform-index-operations-online.md).
50+
The preferred way to build indexes on large tables is to start with the clustered index and then build any nonclustered indexes. Consider setting the `ONLINE` option to `ON` when you create indexes on existing tables. When set to `ON`, long-term table locks aren't held. This enables queries or updates to the underlying table to continue. For more information, see [Perform index operations online](perform-index-operations-online.md).
5151

5252
- The index key of a clustered index can't contain **varchar** columns that have existing data in the `ROW_OVERFLOW_DATA` allocation unit. If a clustered index is created on a **varchar** column and the existing data is in the `IN_ROW_DATA` allocation unit, subsequent insert or update actions on the column that would push the data off-row fail. To obtain information about tables that might contain row-overflow data, use the [sys.dm_db_index_physical_stats (Transact-SQL)](../system-dynamic-management-views/sys-dm-db-index-physical-stats-transact-sql.md) dynamic management function.
5353

@@ -89,7 +89,7 @@ Requires `ALTER` permission on the table or view. User must be a member of the *
8989

9090
1. Select the new index in the **Selected Primary/Unique Key or Index** text box.
9191

92-
1. In the grid, select **Create as Clustered**, and choose **Yes** from the drop-down list to the right of the property.
92+
1. In the grid, select **Create as Clustered**, and choose **Yes** from the dropdown list to the right of the property.
9393

9494
1. Select **Close**.
9595

@@ -106,24 +106,24 @@ Requires `ALTER` permission on the table or view. User must be a member of the *
106106
```sql
107107
USE AdventureWorks2022;
108108
GO
109-
109+
110110
-- Create a new table with three columns.
111111
CREATE TABLE dbo.TestTable (
112112
TestCol1 INT NOT NULL,
113113
TestCol2 NCHAR(10) NULL,
114114
TestCol3 NVARCHAR(50) NULL
115115
);
116116
GO
117-
117+
118118
-- Create a clustered index called IX_TestTable_TestCol1
119119
-- on the dbo.TestTable table using the TestCol1 column.
120120
CREATE CLUSTERED INDEX IX_TestTable_TestCol1 ON dbo.TestTable (TestCol1);
121121
GO
122122
```
123123

124-
For more information, see [CREATE INDEX (Transact-SQL)](../../t-sql/statements/create-index-transact-sql.md).
124+
For more information, see [CREATE INDEX](../../t-sql/statements/create-index-transact-sql.md).
125125

126126
## Related content
127127

128-
- [Create Primary Keys](../tables/create-primary-keys.md)
128+
- [Create primary keys](../tables/create-primary-keys.md)
129129
- [Create unique constraints](../tables/create-unique-constraints.md)

docs/relational-databases/indexes/create-nonclustered-indexes.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Create Nonclustered Indexes
33
description: This article shows you how to create nonclustered indexes by using SQL Server Management Studio or Transact-SQL.
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.date: 09/16/2024
6+
ms.date: 09/02/2025
77
ms.service: sql
88
ms.subservice: table-view-index
99
ms.topic: how-to
@@ -21,36 +21,49 @@ monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-20
2121

2222
[!INCLUDE [SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB](../../includes/applies-to-version/sql-asdb-asdbmi-fabricsqldb.md)]
2323

24-
2524
You can create nonclustered indexes in [!INCLUDE [ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)]. A nonclustered index is an index structure separate from the data stored in a table that reorders one or more selected columns. Nonclustered indexes can often help you find data more quickly than searching the underlying table; queries can sometimes be answered entirely by the data in the nonclustered index, or the nonclustered index can point the [!INCLUDE [ssDE](../../includes/ssde-md.md)] to the rows in the underlying table. Generally, nonclustered indexes are created to improve the performance of frequently used queries not covered by the clustered index or to locate rows in a table without a clustered index (called a heap). You can create multiple nonclustered indexes on a table or indexed view.
2625

27-
## <a name="BeforeYouBegin"></a> Before you begin
26+
<a id="BeforeYouBegin"></a>
27+
28+
## Before you begin
29+
30+
<a id="Implementations"></a>
2831

29-
### <a name="Implementations"></a> Typical implementations
32+
### Typical implementations
3033

3134
Nonclustered indexes are implemented in the following ways:
3235

33-
- **UNIQUE constraints**
36+
- `UNIQUE` constraints**
3437

35-
When you create a UNIQUE constraint, a unique nonclustered index is created to enforce a UNIQUE constraint by default. You can specify a unique clustered index if a clustered index on the table does not already exist. For more information, see [Unique Constraints and Check Constraints](../../relational-databases/tables/unique-constraints-and-check-constraints.md).
38+
When you create a `UNIQUE` constraint, a unique nonclustered index is created to enforce a `UNIQUE` constraint by default. You can specify a unique clustered index if a clustered index on the table doesn't already exist. For more information, see [Unique constraints and check constraints](../tables/unique-constraints-and-check-constraints.md).
3639

3740
- **Index independent of a constraint**
3841

39-
By default, a nonclustered index is created if clustered is not specified. The maximum number of nonclustered indexes that can be created per table is 999. This includes any indexes created by PRIMARY KEY or UNIQUE constraints, but does not include XML indexes.
42+
By default, a nonclustered index is created if clustered isn't specified. The maximum number of nonclustered indexes that can be created per table is 999. This includes any indexes created by `PRIMARY KEY` or `UNIQUE` constraints, but doesn't include XML indexes.
4043

4144
- **Nonclustered index on an indexed view**
4245

43-
After a unique clustered index has been created on a view, nonclustered indexes can be created. For more information, see [Create indexed views](../../relational-databases/views/create-indexed-views.md).
46+
After a unique clustered index has been created on a view, nonclustered indexes can be created. For more information, see [Create indexed views](../views/create-indexed-views.md).
47+
48+
<a id="Security"></a>
49+
50+
### Security
51+
52+
<a id="Permissions"></a>
4453

45-
### <a name="Security"></a> Security
54+
#### Permissions
4655

47-
#### <a name="Permissions"></a> Permissions
56+
Requires `ALTER` permission on the table or view. User must be a member of the **sysadmin** fixed server role or the **db_ddladmin** and **db_owner** fixed database roles.
4857

49-
Requires ALTER permission on the table or view. User must be a member of the **sysadmin** fixed server role or the **db_ddladmin** and **db_owner** fixed database roles.
58+
<a id="SSMSProcedure"></a>
5059

51-
## <a name="SSMSProcedure"></a> Using SQL Server Management Studio
60+
<a id="using-sql-server-management-studio"></a>
5261

53-
### To create a nonclustered index by using the Table Designer
62+
## Use SQL Server Management Studio
63+
64+
<a id="to-create-a-nonclustered-index-by-using-the-table-designer"></a>
65+
66+
### Create a nonclustered index by using the Table Designer
5467

5568
1. In Object Explorer, expand the database that contains the table on which you want to create a nonclustered index.
5669

@@ -70,7 +83,9 @@ Requires ALTER permission on the table or view. User must be a member of the **s
7083

7184
1. On the **File** menu, select **Save** _table_name_.
7285

73-
### To create a nonclustered index by using Object Explorer
86+
<a id="to-create-a-nonclustered-index-by-using-object-explorer"></a>
87+
88+
### Create a nonclustered index by using Object Explorer
7489

7590
1. In Object Explorer, expand the database that contains the table on which you want to create a nonclustered index.
7691

@@ -90,30 +105,36 @@ Requires ALTER permission on the table or view. User must be a member of the **s
90105

91106
1. In the **New Index** dialog box, select **OK**.
92107

93-
## <a name="TsqlProcedure"></a> Using Transact-SQL
108+
<a id="TsqlProcedure"></a>
109+
110+
<a id="using-transact-sql"></a>
111+
112+
## Use Transact-SQL
113+
114+
<a id="to-create-a-nonclustered-index-on-a-table-using-transact-sql"></a>
94115

95-
### To create a nonclustered index on a table using Transact-SQL
116+
### Create a nonclustered index on a table using Transact-SQL
96117

97118
1. In **Object Explorer**, connect to an instance of [!INCLUDE [ssDE](../../includes/ssde-md.md)] with [!INCLUDE [sssampledbobject-md](../../includes/sssampledbobject-md.md)] installed. You can download [!INCLUDE [sssampledbobject-md](../../includes/sssampledbobject-md.md)] from [sample databases](../../samples/adventureworks-install-configure.md?view=sql-server-ver15&tabs=ssms&preserve-view=true).
98119

99120
1. On the Standard bar, select **New Query**.
100121

101122
1. Copy and paste the following example into the query window and select **Execute**.
102123

103-
```sql
104-
USE AdventureWorks2022;
105-
GO
106-
-- Find an existing index named IX_ProductVendor_VendorID and delete it if found.
107-
IF EXISTS (SELECT name FROM sys.indexes
108-
WHERE name = N'IX_ProductVendor_VendorID')
109-
DROP INDEX IX_ProductVendor_VendorID ON Purchasing.ProductVendor;
110-
GO
111-
-- Create a nonclustered index called IX_ProductVendor_VendorID
112-
-- on the Purchasing.ProductVendor table using the BusinessEntityID column.
113-
CREATE NONCLUSTERED INDEX IX_ProductVendor_VendorID
114-
ON Purchasing.ProductVendor (BusinessEntityID);
115-
GO
116-
```
124+
```sql
125+
USE AdventureWorks2022;
126+
GO
127+
-- Find an existing index named IX_ProductVendor_VendorID and delete it if found.
128+
IF EXISTS (SELECT name FROM sys.indexes
129+
WHERE name = N'IX_ProductVendor_VendorID')
130+
DROP INDEX IX_ProductVendor_VendorID ON Purchasing.ProductVendor;
131+
GO
132+
-- Create a nonclustered index called IX_ProductVendor_VendorID
133+
-- on the Purchasing.ProductVendor table using the BusinessEntityID column.
134+
CREATE NONCLUSTERED INDEX IX_ProductVendor_VendorID
135+
ON Purchasing.ProductVendor (BusinessEntityID);
136+
GO
137+
```
117138

118139
## Related content
119140

0 commit comments

Comments
 (0)