甲骨文发现制约因素


Answers:


267
select * from all_constraints
where owner = '<NAME>'
and constraint_name = 'SYS_C00381400'
/

像所有数据字典视图一样,如果您只想检查当前架构,则为USER_CONSTRAINTS视图;对于管理用户,则为DBA_CONSTRAINTS视图。

约束名称的构造指示系统生成的约束名称。例如,如果我们在表声明中指定NOT NULL。或者实际上是主键或唯一键。例如:

SQL> create table t23 (id number not null primary key)
  2  /

Table created.

SQL> select constraint_name, constraint_type
  2  from user_constraints
  3  where table_name = 'T23'
  4  /

CONSTRAINT_NAME                C
------------------------------ -
SYS_C00935190                  C
SYS_C00935191                  P

SQL>

'C'检查,'P'主要。

通常,给关系约束一个明确的名称是一个好主意。例如,如果数据库为主键创建索引(如果尚未为该列创建索引,它将执行该操作),它将使用约束名称或名称索引。您不希望数据库中充满名为like的索引SYS_C00935191

老实说,大多数人都不会打扰命名NOT NULL约束。


25

要获取更详细的描述(哪个表/列引用哪个表/列),可以运行以下查询:

SELECT   uc.constraint_name||CHR(10)
   ||      '('||ucc1.TABLE_NAME||'.'||ucc1.column_name||')' constraint_source
   ,       'REFERENCES'||CHR(10)
   ||      '('||ucc2.TABLE_NAME||'.'||ucc2.column_name||')' references_column
FROM user_constraints uc ,
  user_cons_columns ucc1 ,
  user_cons_columns ucc2
WHERE uc.constraint_name = ucc1.constraint_name
AND uc.r_constraint_name = ucc2.constraint_name
AND ucc1.POSITION        = ucc2.POSITION -- Correction for multiple column primary keys.
AND uc.constraint_type   = 'R'
AND uc.constraint_name   = 'SYS_C00381400'
ORDER BY ucc1.TABLE_NAME ,
  uc.constraint_name;

这里


6

也许这可以帮助..

SELECT constraint_name, constraint_type, column_name
from user_constraints natural join user_cons_columns
where table_name = "my_table_name";
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.