在Oracle SQL中显示表的所有约束的名称
我已经为在Oracle SQL中创build的多个表的每个约束定义了一个名称。
问题是,要删除特定表的列的约束,我需要知道我为每个约束提供的名称,我已经忘记了。
如何列出我为表的每一列指定的所有约束名称?
有没有这样做的SQL语句?
您需要查询数据字典 ,特别是USER_CONS_COLUMNS视图,以查看表列和相应的约束条件: 
 SELECT * FROM user_cons_columns WHERE table_name = '<your table name>'; 
仅供参考,除非您专门使用小写字母名称(使用双引号)创build表格,否则表格名称将默认为大写,因此请确保在查询中如此。
 如果您希望查看有关约束本身的更多信息,请查询USER_CONSTRAINTS视图: 
 SELECT * FROM user_constraints WHERE table_name = '<your table name>' AND constraint_name = '<your constraint name>'; 
如果表格保存在不是默认模式的模式中,那么您可能需要将视图replace为:
 all_cons_columns 
和
 all_constraints 
添加到where子句中:
  AND owner = '<schema owner of the table>' 
 SELECT * FROM USER_CONSTRAINTS 
 select constraint_name,constraint_type from user_constraints where table_name = 'YOUR TABLE NAME'; 
注意:表名应该在大写字母上。
如果你不知道表的名字,
 select constraint_name,constraint_type,table_name from user_constraints; 
也许这可以帮助:
 SELECT constraint_name, constraint_type, column_name from user_constraints natural join user_cons_columns where table_name = "my_table_name"; 
干杯