Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will I miss any changes if I replace an oracle trigger while my application is running?

I'm wondering if I will miss any data if I replace a trigger while my oracle database is in use. I created a toy example and it seems like I won't, but one of my coworkers claims otherwise.

create table test_trigger (id number);
create table test_trigger_h (id number);
create sequence test_trigger_seq;

--/
create or replace trigger test_trigger_t after insert on test_trigger for each row
begin
  insert into test_trigger_h (id) values (:new.id);
end;    
/

--/
begin
  for i in 1..100000 loop
    insert into test_trigger (id) values (test_trigger_seq.nextval);
  end loop;
end;
/

--/
begin
  for i in 1..10000 loop
    execute immediate 'create or replace trigger test_trigger_t after insert on test_trigger for each row begin insert into test_trigger_h (id) values (:new.id); end;';
  end loop;
end;
/

ran the two loops at the same time

select count(1) from test_trigger;

COUNT(1)
100000

select count(1) from test_trigger_h;

COUNT(1)
100000
like image 937
NotALamer Avatar asked Aug 26 '13 22:08

NotALamer


People also ask

Which key trigger and function is used for deleting the current record?

DELETE Trigger is a data manipulation language (DML) trigger in SQL. A stored procedure on a database object gets invoked automatically instead of before or after a DELETE command has been successfully executed on the said database table.

Is it possible to create the following trigger before or after update trigger for each row?

Old and new values are available in both BEFORE and AFTER row triggers. A new column value can be assigned in a BEFORE row trigger, but not in an AFTER row trigger (because the triggering statement takes effect before an AFTER row trigger is fired).

How many triggers can be applied to a table?

A single SQL statement can potentially fire up to four types of triggers: BEFORE row triggers, BEFORE statement triggers, AFTER row triggers, and AFTER statement triggers.

How do you check if trigger is executed in Oracle?

user_triggers is the table where all triggers created, specific to the schema, are located. So, SELECT STATUS FROM USER_TRIGGERS WHERE TRIGGER_NAME = 'the_trigger_name'; will fetch the status of either ENABLED or DISABLED .


1 Answers

create or replace is locking the table. So all the inserts will wait until it completes. Don't worry about missed inserts.

like image 160
Dmitry Ulupov Avatar answered Oct 04 '22 20:10

Dmitry Ulupov