Dav*_*ill 154 sql oracle constraints
我有一个叫做的约束users.SYS_C00381400
.我如何找到该约束是什么?有没有办法查询所有约束?
APC*_*APC 248
select * from all_constraints
where owner = '<NAME>'
and constraint_name = 'SYS_C00381400'
/
Run Code Online (Sandbox Code Playgroud)
与所有数据字典视图一样,如果您只想检查当前架构和管理用户的DBA_CONSTRAINTS视图,则为USER_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>
Run Code Online (Sandbox Code Playgroud)
'C'
检查,'P'
主要.
通常,为关系约束提供一个明确的名称是个好主意.例如,如果数据库为主键创建索引(如果该列尚未编入索引,则会执行该索引),它将使用约束名称命名索引.您不希望数据库中包含名为的索引SYS_C00935191
.
大多数人都不打算命名NOT NULL约束.
Thi*_*ago 24
要获得更详细的描述(哪个表/列引用哪个表/列),您可以运行以下查询:
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;
Run Code Online (Sandbox Code Playgroud)
从这里开始.
我发现这个是最有帮助的:
select * from ALL_CONS_COLUMNS
where constraint_name = 'SYS_C00381400';
Run Code Online (Sandbox Code Playgroud)
它返回表名和列名,例如
OWNER,CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME,POSITION
MY_OWNER,SYS_C00381400,MY_TABLE,MY_COLUMN,1
Run Code Online (Sandbox Code Playgroud)
也许这可以帮助..
SELECT constraint_name, constraint_type, column_name
from user_constraints natural join user_cons_columns
where table_name = "my_table_name";
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
262366 次 |
最近记录: |