SQL Query to Drop Unique Key Constraints Using ALTER Command
Last Updated :
19 Apr, 2021
Here, we see how to drop unique constraints using alter command. ALTER is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.
Syntax :
ALTER TABLE table_name
DROP CONSTRAINT unique_constraint;
For instance, consider the below table 'Employee'.
Create a Table:
CREATE TABLE Employee
('ID INT, F_Name CHAR(10), L_Name CHAR(10), Age INT);
Insert values to the table:
INSERT INTO Employee
VALUES('1','Rahul','Pal','20');
INSERT INTO Employee
VALUES('2','Ajay','Soni','32');
INSERT INTO Employee
VALUES('3','Jay','Harjai','24');
INSERT INTO Employee
VALUES('4','Ram','Meena','30');
Our table at this point will look like below:
Employee

ADD Unique Constraint Using ALTER:
To add a unique constraint to the table use the below statement:
ALTER TABLE Employee
ADD CONSTRAINT/INDEX unique_id UNIQUE (ID);
Now, if we add duplicates to it. It will throw the error as below. In order to add duplicates, we need to Drop Unique constraints.

DROP Unique Constraints Query:
Now the below query can be used to drop the unique constraint that we created above:
ALTER TABLE Employee
DROP CONSTRAINT unique_id;
Now let's try an add duplicates in the table:
INSERT INTO Employee
VALUES('4', 'ABC', 'XYZ', '35');
Since we didn't get an error, we have successfully removed the unique constraint. Let's check out the tables to verify the same using the below statement:
SELECT * FROM Employee;
Output:
Employee
Similar Reads
SQL Query to Add Unique key Constraints Using ALTER Command Here we will see how to add unique key constraint to a column(s) of a MS SQL Server's database with the help of a SQL query using ALTER clause. For the demonstration purpose, we will be creating a demo table in a database called "geeks". Creating the Database : Use the below SQL statement to create
2 min read
SQL Query to Add Foreign Key Constraints Using ALTER Command In relational databases, a Foreign Key Constraint is a fundamental concept that defines a relationship between two tables. It ensures that the value of one or more columns in a child table corresponds to the value in a primary key or unique key in a parent table.In this article, we will look into ho
3 min read
How to Create Unique Constraint with NULL Columns in SQL In SQL databases, maintaining data integrity is crucial, and one common requirement is applying uniqueness among certain columns. However, handling NULL values in these columns can be challenging. By creating a unique constraint with NULL columns, we can ensure that non-NULL values are unique while
5 min read
How to Use SQL Query to Rename a Constraint? In SQL, we sometimes need to rename the constraints of a table. The whole process for doing the same is demonstrated below. For this article, we will be using the Microsoft SQL Server as our database. Step 1: Create a Database. For this use the below command to create a database named GeeksForGeeks.
2 min read
Create Unique Constraint with NULL Columns in MySQL Unique constraint in MySQL ensures that each value in the column is unique. If a column contains a NULL value, it is also treated as a unique value, but if a column contains multiple NULL values it can not have a unique constraint.In this article we will look over how we can Create unique constraint
3 min read