0 votes
1 view
in SQL by (20.3k points)

I have defined a name for each of the constraints for the multiple tables that I have created in Oracle SQL.

The problem is that to drop a constraint for the column of a particular table I need to know the name that I have supplied for each constraint, which I have forgotten.

How do I list out all the names of constraints that I have specified for each column of a table?

Is there any SQL statement for doing so?

1 Answer

0 votes
by (40.4k points)

You have to query the data dictionary, specially the USER_CONS_COLUMNS view to see the table columns and the corresponding constraints like this:

SELECT *

FROM user_cons_columns

WHERE table_name = '<your table name>';

Unless you are creating the table with the lower case name (by using double quotes) then the table name must be defaulted to upper case hence ensure it is so in the query.

But, if you wish to see more information about the constraint itself query the USER_CONSTRAINTS view like this:

SELECT *

  FROM user_constraints

 WHERE table_name = '<your table name>'

   AND constraint_name = '<your constraint name>';

But, if the table is held in the schema that is not your default schema then you might need to replace the views with:

all_cons_columns

and

all_constraints

adding to the where clause:

AND owner = '<schema owner of the table>'

If you wish to learn more about tables in SQL then visit this blog on SQL Table.

You can master these queries and become proficient in SQL queries by enrolling in an industry-recognized SQL certification.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 16, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...