Display names of all constraints for a table in Oracle SQL

前端 未结 6 795
失恋的感觉
失恋的感觉 2020-11-29 16:19

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

The problem is that to drop a constraint for the column

6条回答
  •  忘掉有多难
    2020-11-29 17:14

    You need to query the data dictionary, specifically the USER_CONS_COLUMNS view to see the table columns and corresponding constraints:

    SELECT *
      FROM user_cons_columns
     WHERE table_name = '';
    

    FYI, unless you specifically created your table with a lower case name (using double quotes) then the table name will be defaulted to upper case so ensure it is so in your query.

    If you then wish to see more information about the constraint itself query the USER_CONSTRAINTS view:

    SELECT *
      FROM user_constraints
     WHERE table_name = ''
       AND constraint_name = '';
    

    If the table is held in a 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 = ''
    

提交回复
热议问题