Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop a unique constraint from table column?

Tags:

I have a table 'users' with 'login' column defined as:

[login] VARCHAR(50) UNIQUE NOT NULL 

Now I want to remove this unique constraint/index using SQL script. I found its name UQ_users_7D78A4E7 in my local database but I suppose it has a different name on another database.

What is the best way to drop this unique constraint? Or at least any...

Thanks.

like image 356
SKINDER Avatar asked Mar 31 '11 12:03

SKINDER


People also ask

How do you remove a unique key from a column?

First you need to know the exact name of the INDEX (Unique key in this case) to delete or update it. INDEX names are usually same as column names. In case of more than one INDEX applied on a column, MySQL automatically suffixes numbering to the column names to create unique INDEX names.

How do you drop a unique constraint in Oracle?

The syntax for dropping a unique constraint in Oracle is: ALTER TABLE table_name DROP CONSTRAINT constraint_name; table_name.


1 Answers

ALTER TABLE users DROP CONSTRAINT 'constraints_name' 

if earlier constraints_name is not provided, it will have some default constraint_name, in pgAdmin 4 (pSql), try violating the constraint and you can see the constraint_name being violated in the error received, most probably same must be the case with other platforms or there are some articles available over web where constraint_name is extracted from certain tables where they are stored, not sure about this though. P.S : Can take reference from comments also

like image 95
Avadhesh Avatar answered Oct 10 '22 15:10

Avadhesh