Skip to content

清空带有外键的表数据

--禁用当前登录用户下的所有外键
select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R';

--清空表数据
select 'truncate table '|| table_name ||';' from user_tables where table_name not like 'TB_SYS%';

--启用当前登录用户下的所有外键
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R';

--删除并创建序列
select 'drop sequence '||sequence_name||';' name from user_sequences union all
select 'create sequence '||sequence_name||';' name from user_sequences
order by name desc;