| SELECT | cons.constraint_name "Name", cons.constraint_type "Type", cons.search_condition "Condition", |
| cons.r_owner, cons.r_constraint_name, col.column_name "Column Name", col.position | |
| FROM | all_constraints cons, all_cons_columns col |
| WHERE | cons.owner = col.owner |
| AND | cons.table_name = col.table_name |
| AND | cons.constraint_name = col.constraint_name |
| AND | cons.table_name = '&&Table' |
| / |
To run the code, cut and paste it onto your favourite editor and save the file to say constraints.sql.
At the SQL*PLUS prompt, execute the script using the syntax 'SQL>@constraints'. The script prompts you for the name of the table. It
then displays information w.r.t the all constraints created for the table. (If you want to see information about the foreign keys, see
the script to find foreign keys and the corresponding information
For the emp table, for example, you get the
following output.
SQL>@constraints
Please enter your table name: EMP
| Wed May 09 | page 1 | |||||
| Constraints specified | for table EMP | |||||
| Name | Type | Condition | R_OWNER | R_CONSTRAINT_NAME | Column Name | POSITION |
| -------------------- | ---- | --------------------- | ------------------- | ----------------------------------------- | --------- | ---------- |
| PK_EMP | P | EMPNO | 1 | |||
| FK_DEPTNO | R | SCOTT | PK_DEPT | DEPTNO | 1 |