Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get table name by constraint name [duplicate]

Oracle constraint name is known.

How do I find the name of the table for which this constraint is applied?

like image 315
sergionni Avatar asked Mar 09 '11 15:03

sergionni


People also ask

How do you find the table name based on constraints?

Use the view table_constraints in the information_schema schema. The column table_name gives you the name of the table in which the constraint is defined, and the column constraint_name contains the name of the constraint.

Can 2 tables have the same constraint name?

No - a constraint is a database object as well, and thus its name needs to be unique.

How would you use User_constraints table in DB?

Discussion: In Oracle, use the view user_constraints to display the names of the constraints in the database. The column constraint_name contains the name of the constraint, constraint_type indicates the type of constraint, and table_name contains the name of the table to which the constraint belongs.


2 Answers

SELECT owner, table_name   FROM dba_constraints  WHERE constraint_name = <<your constraint name>> 

will give you the name of the table. If you don't have access to the DBA_CONSTRAINTS view, ALL_CONSTRAINTS or USER_CONSTRAINTS should work as well.

like image 160
Justin Cave Avatar answered Sep 28 '22 21:09

Justin Cave


ALL_CONSTRAINTS describes constraint definitions on tables accessible to the current user.

DBA_CONSTRAINTS describes all constraint definitions in the database.

USER_CONSTRAINTS describes constraint definitions on tables in the current user's schema

Select CONSTRAINT_NAME,CONSTRAINT_TYPE ,TABLE_NAME ,STATUS from  USER_CONSTRAINTS; 
like image 35
Suprriya Avatar answered Sep 28 '22 19:09

Suprriya