MySQL
unique constraint
SQL tutorial
database management
SQL commands

How to drop unique in MySQL?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In MySQL, a UNIQUE constraint is enforced through a unique index. That means removing uniqueness is usually a matter of dropping the underlying index by name. The important part is identifying the correct index first, especially when the constraint was created automatically or across multiple columns.

Find the Name of the Unique Index

Before dropping anything, inspect the table definition. The easiest way is SHOW CREATE TABLE.

sql
SHOW CREATE TABLE users;

Example output might contain something like:

sql
1CREATE TABLE `users` (
2  `id` bigint NOT NULL AUTO_INCREMENT,
3  `email` varchar(255) NOT NULL,
4  PRIMARY KEY (`id`),
5  UNIQUE KEY `email` (`email`)
6);

In this case, the unique index is named email. You can also list indexes directly:

sql
SHOW INDEX FROM users;

That is often clearer when a table has several indexes.

Drop the Unique Constraint With ALTER TABLE

Once you know the index name, drop it with ALTER TABLE ... DROP INDEX.

sql
ALTER TABLE users DROP INDEX email;

After that statement succeeds, the column is no longer protected by uniqueness, and duplicate values can be inserted.

In MySQL, this is the normal way to remove a unique constraint. There is no separate DROP CONSTRAINT syntax for ordinary unique indexes like there is in some other database systems.

Example With a Composite Unique Constraint

A unique constraint can span more than one column. For example:

sql
1CREATE TABLE enrollments (
2  id bigint NOT NULL AUTO_INCREMENT,
3  student_id bigint NOT NULL,
4  course_id bigint NOT NULL,
5  PRIMARY KEY (id),
6  UNIQUE KEY uniq_student_course (student_id, course_id)
7);

To remove it:

sql
ALTER TABLE enrollments DROP INDEX uniq_student_course;

After dropping the index, the same student and course pair can appear more than once.

Be Careful With Automatically Chosen Names

If you created the table through a migration tool or ORM, the unique index name may not match the column name. That is why guessing can waste time. Always inspect the actual schema first.

For example, a migration tool might create:

sql
UNIQUE KEY `users_email_unique` (`email`)

Then the correct command would be:

sql
ALTER TABLE users DROP INDEX users_email_unique;

Using the column name by mistake would fail because MySQL drops indexes by index name, not by column reference.

Verify the Result

After the change, confirm the unique index is gone:

sql
SHOW INDEX FROM users;

Or inspect the full table definition again:

sql
SHOW CREATE TABLE users;

Verification matters because some tables have both a unique index and a separate nonunique index on related columns, and you want to be sure you removed the intended one.

Consider the Data Model Before Removing Uniqueness

Dropping a unique constraint is easy technically, but it changes the rules of the table. If the application previously assumed every email, username, or external ID was unique, queries and business logic can break.

Typical consequences include:

  • duplicate user accounts
  • ambiguous lookup queries
  • failed assumptions in joins
  • broken upsert logic based on uniqueness

If duplicates will now be allowed, it is worth reviewing validation code and any reports or APIs that assumed uniqueness.

Replacing the Constraint Instead of Just Dropping It

Sometimes the real requirement is not "remove uniqueness completely" but "change which columns must be unique." In that case, drop the old unique index and create a new one.

sql
ALTER TABLE users DROP INDEX email;
ALTER TABLE users ADD UNIQUE KEY uniq_email_company (email, company_id);

That pattern is common in multi-tenant applications where a field should be unique only within a tenant or organization.

Common Pitfalls

The biggest mistake is trying to use DROP CONSTRAINT syntax copied from another database engine. In MySQL, ordinary unique constraints are dropped as indexes. Another common issue is guessing the index name instead of checking SHOW CREATE TABLE or SHOW INDEX. Developers also remove uniqueness without realizing application logic depends on it. Composite unique indexes deserve extra care because dropping them changes rules across several columns at once. Finally, schema changes on large production tables should be planned carefully because index changes can still affect performance and deployment timing.

Summary

  • In MySQL, a UNIQUE constraint is usually enforced by a unique index.
  • Find the real index name with SHOW CREATE TABLE or SHOW INDEX.
  • Remove it with ALTER TABLE table_name DROP INDEX index_name.
  • Composite unique constraints are dropped the same way.
  • Verify the schema after the change.
  • Review application logic before allowing duplicate values.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.