【问题标题】:Truncate all tables and reset autoincrement截断所有表并重置自动增量
【发布时间】:2020-05-10 02:07:19
【问题描述】:

需要为生产环境准备Oracle数据库中的所有表,并且需要截断所有表,并重置列的自动增量。我该怎么做?

【问题讨论】:

  • 自动递增列?你说的是身份栏吗?
  • 是的关于身份

标签: oracle truncate


【解决方案1】:

这就是我要做的-

运行以下命令以生成截断语句。请注意,它不会截断表格

select ' truncate table  ' || table_name || ';' from user_tables;

查看脚本并确保这是我想要的。然后我将运行脚本。

通过首先生成语句对序列做类似的事情,如下所示:

--Reset regular sequences.
--(Ignore identity sequences to avoid "ORA-32793: cannot alter a system-generated sequence".)
select 'alter sequence ' || sequence_name || ' restart start with 1;' v_sql
from user_sequences
where sequence_name not in (select sequence_name from user_tab_identity_cols)
order by 1;

--Reset sequences used in identity columns.
select 'alter table ' || table_name || ' modify ' ||
    '(' || column_name || ' generated by default on null as identity start with 1);' v_sql
from user_tab_identity_cols
order by 1;

【讨论】:

  • 谢谢,我会试试的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 2016-03-13
  • 2017-01-02
  • 1970-01-01
  • 2019-05-11
相关资源
最近更新 更多