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 delete (drop) a primary key in SQL Server by using SQL Server Management Studio or Transact-SQL.
When the primary key is deleted, the corresponding index is deleted. This index might be the clustered index of the table, causing the table to become a heap. For more information, see Heaps (tables without clustered indexes). Most tables should have a clustered index. To re-create the primary key, see Create primary keys.
Primary keys can be referenced by foreign keys in another table. If referenced by a foreign key, you need to drop referencing foreign keys first, then drop the primary key. For more information, see Primary and foreign key constraints.
Requires ALTER
permission on the table.
In Object Explorer, expand the table that contains the primary key and then expand Keys.
Right-click the key and select Delete.
In the Delete Object dialog box, verify the correct key is specified and select OK.
In Object Explorer, right-click the table with the primary key, and select Design.
In the table grid, right-click the row with the primary key and choose Remove Primary Key to toggle the setting from on to off.
Note
To undo this action, close the table without saving the changes. Deleting a primary key can't be undone without losing all other changes made to the table.
On the File menu, select Save table name.
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, select New Query.
Copy and paste the following example into the query window and select Execute.
You must first identify the name of the primary key constraint.
USE AdventureWorks2022;
GO
-- Return the name of primary key.
SELECT name
FROM sys.key_constraints
WHERE type = 'PK'
AND OBJECT_NAME(parent_object_id) = N'TransactionHistoryArchive';
GO
To create the DROP
script, use the result from the previous query. Replace <primary-key-constraint>
with the correct value. It might look similar to PK_TransactionHistoryArchive_TransactionID
.
ALTER TABLE Production.TransactionHistoryArchive
DROP CONSTRAINT <primary-key-constraint>;
GO
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
Module
Design a Performant Data Model in Azure SQL Database with Azure Data Studio - Training
Learn how to create a data model, tables, indexes, constraints, and use data types with Azure data studio.
Documentation
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.
Modify Primary Keys - SQL Server
Modify Primary Keys
ALTER TABLE (Transact-SQL) - SQL Server
ALTER TABLE modifies a table definition by altering, adding, or dropping columns and constraints. ALTER TABLE also reassigns and rebuilds partitions, or disables and enables constraints and triggers.