im8*_*bit 3 oracle constraints
我想禁用NOT NULL约束到表中插入数据进行测试,但我找不到禁用未命名约束的方法.
我找到了足够的信息来禁用命名约束,但我找不到禁用未命名的NOT NULL约束的示例.
我想在不查询数据字典的情况下实现这一点,但是......如果它是唯一的方法,我愿意这样做.但我想使用干净的ALTER TABLE DDL.
您将需要查询数据字典,类似这样的操作将禁用表上的所有约束。但是请注意,这将禁用整个系统的约束,而不仅仅是在您的会话中。也许您真正想要的是推迟约束?
drop table testxx
drop table testxx succeeded.
create table testxx ( id number not null )
create table succeeded.
select status from user_constraints where table_name = 'TESTXX'
STATUS
--------
ENABLED
1 rows selected
begin
for cnames in ( select table_name,constraint_name from user_constraints where table_name = 'TESTXX' ) loop
execute immediate 'alter table ' || cnames.table_name || ' disable constraint ' || cnames.constraint_name;
end loop;
end;
anonymous block completed
select status from user_constraints where table_name = 'TESTXX'
STATUS
--------
DISABLED
1 rows selected
Run Code Online (Sandbox Code Playgroud)
您也可以按如下方式更改列
create table test_null (col_n number not null);
alter table test_null modify col_n number null;
Run Code Online (Sandbox Code Playgroud)