Skip to content

Latest commit

 

History

History
89 lines (59 loc) · 3.22 KB

delete-unique-constraints.md

File metadata and controls

89 lines (59 loc) · 3.22 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords monikerRange
Delete Unique Constraints
Delete Unique Constraints
WilliamDAssafMSFT
wiassaf
10/12/2016
sql
table-view-index
conceptual
removing constraints
UNIQUE constraints [SQL Server], deleting
constraints [SQL Server], deleting
deleting constraints
constraints [SQL Server], unique
=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

Delete Unique Constraints

[!INCLUDE sqlserver2016-asdb-asdbmi]

You can delete a unique constraint in [!INCLUDEssnoversion] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql]. Deleting a unique constraint removes the requirement for uniqueness for values entered in the column or combination of columns included in the constraint expression and deletes the corresponding unique index.

In This Topic

Before You Begin

Security

Permissions

Requires ALTER permission on the table.

Using SQL Server Management Studio

To delete a unique constraint using Object Explorer

  1. In Object Explorer, expand the table that contains the unique constraint and then expand Constraints.

  2. Right-click the key and select Delete.

  3. In the Delete Object dialog box, verify the correct key is specified and click OK.

To delete a unique constraint using Table Designer

  1. In Object Explorer, right-click the table with the unique constraint, and click Design.

  2. On the Table Designer menu, click Indexes/Keys.

  3. In the Indexes/Keys dialog box, select the unique key in the Selected Primary/Unique Key and Index list.

  4. Click Delete.

  5. On the File menu, click Save table name.

Using Transact-SQL

To delete a unique constraint

  1. In Object Explorer, connect to an instance of [!INCLUDEssDE].

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute.

    -- Return the name of unique constraint.  
    SELECT name  
    FROM sys.objects  
    WHERE type = 'UQ' AND OBJECT_NAME(parent_object_id) = N' DocExc';  
    GO  
    -- Delete the unique constraint.  
    ALTER TABLE dbo.DocExc   
    DROP CONSTRAINT UNQ_ColumnB_DocExc;  
    GO  
    

For more information, see ALTER TABLE (Transact-SQL) and sys.objects (Transact-SQL).