【发布时间】:2021-05-29 11:10:45
【问题描述】:
我正在使用 Oracle XE。 当我删除表时,有什么方法可以自动删除触发器和序列? 这是我的表、序列和触发器:
create table country(
country_id number(5) primary key,
country varchar2(36),
country_code varchar2(3)
);
create sequence country_seq
start with 1 increment by 1;
create or replace trigger country_trig
before insert on country
referencing new as new
for each row
begin
select country_seq.nextval into :new.country_id from dual;
end;
/
我在删除主表记录时使用它,然后子表的所有记录都自动删除
【问题讨论】:
-
删除表时删除表的触发器。使用
create sequence创建的独立序列不与任何表关联,但作为标识列一部分的内部序列会随表一起删除,因此这取决于您的意思。不过,我不确定您的外键示例与该问题有什么关系。 -
an internal sequence that is part of an identity column is dropped with the table怎么样?当我删除表并重新创建它并插入记录时,它会从先前创建的序列中获取值 -
create sequence country_seq * ERROR at line 1: ORA-00955: name is already used by an existing object我的意思是删除表时不删除序列 -
序列
country_seq与任何表均无关联。当您删除某个表时,Oracle 应该如何知道您要删除它?
标签: sql oracle oracle11g oracle-xe