Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2016 (13.x) and later versions
Azure SQL Database
Azure SQL Managed Instance
SQL database in Microsoft Fabric
You can modify a primary key in SQL Server by using SQL Server Management Studio or Transact-SQL. You can modify the primary key of a table by changing the column order, index name, clustered option, or fill factor.
In This Topic
Before you begin:
To modify a primary key, using:
Requires ALTER permission on the table.
Open the Table Designer for the table whose primary key you want to modify, right-click in the Table Designer, and choose Indexes/Keys from the shortcut menu.
In the Indexes/Keys dialog box, select the primary key index from the Selected Primary/Unique Key or Index list.
Complete an action from the following table:
To | Follow these steps |
---|---|
Rename the primary key | Type a new name in the Name box. Make sure that your new name does not duplicate a name in the Selected Primary/Unique Key or Index list. |
Set the clustered option | To create a clustered index for the primary key, select Create as CLUSTERED, and select the option from the drop-down list box. Only one clustered index can exist per table. If this option is not available for your index, you must first clear this setting on the existing clustered index. If this option is not selected, a unique nonclustered index is created. |
Define a fill factor | Expand the Fill Specification category and type an integer from 0 to 100 in the Fill factor box. For more information about fill factors and their uses, see Specify Fill Factor for an Index. |
Change the column order | Select Columns, and then click the ellipses (...) to the right of the property. In the Index Columns dialog box, remove the columns from the primary key. Then add the columns back in the order you want. To remove a column from the key, simply remove the column name from the Column name list. |
On the File menu, click Savetable name.
To modify a primary key
To modify a PRIMARY KEY constraint using Transact-SQL, you must first delete the existing PRIMARY KEY constraint and then re-create it with the new definition. For more information, see Delete Primary Keys and Create Primary Keys.
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Certification
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Documentation
Delete Primary Keys - SQL Server
Learn more about how to delete the primary key from a table in the SQL Server Database Engine.
Create primary keys in SQL Server - SQL Server
Define a primary key in the SQL Server Database Engine by using SQL Server Management Studio or Transact-SQL.
table_constraint (Transact-SQL) - SQL Server
ALTER TABLE table_constraint (Transact-SQL)