Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show unique constraints of a table in MySQL?

Tags:

database

mysql

I created them, but I forgot which ones they are.

I just want to

  1. show them.
  2. remove all the constraints on a table.
like image 332
TIMEX Avatar asked Dec 02 '09 23:12

TIMEX


People also ask

How do you find unique constraints on a table?

To check for a unique constraint use the already provided method: select count(*) cnt from user_constraints uc where uc. table_name='YOUR_TABLE_NAME' and uc.

How do you display the unique section in the table?

The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

How do I view constraints in MySQL?

select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME from information_schema. KEY_COLUMN_USAGE where TABLE_NAME = 'yourTableName'; To display all constraints on a table, implement the above syntax.


1 Answers

select distinct CONSTRAINT_NAME from information_schema.TABLE_CONSTRAINTS where table_name = 'table_name' and constraint_type = 'UNIQUE'; 
like image 69
Dave Avatar answered Oct 02 '22 15:10

Dave