Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
Trigger names are unique within a schema, no matter which table the trigger belongs to. CREATE TRIGGER without OR REPLACE stops with ORA-04081 when the name is taken.
Check USER_TRIGGERS first: if the existing trigger is on the same table, you probably want to replace it; if it is on another table, the new trigger needs its own name.
01Deployment script runs CREATE TRIGGER again
ORDERS_BI was already created by the first deployment. The changed version was deployed with plain CREATE TRIGGER, so Oracle refused it and kept the old trigger.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, amount NUMBER, created_at DATE);
CREATE TRIGGER orders_bi BEFORE INSERT ON orders FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/Table created.
Trigger created.CREATE TRIGGER orders_bi BEFORE INSERT ON orders FOR EACH ROW
BEGIN
:NEW.created_at := NVL(:NEW.created_at, SYSDATE);
END;
/CREATE TRIGGER orders_bi BEFORE INSERT ON orders FOR EACH ROW
*
ERROR at line 1:
ORA-04081: trigger 'ORDERS_BI' already exists
Help: https://docs.oracle.com/error-help/db/ora-04081/COLUMN trigger_name FORMAT A10
COLUMN table_name FORMAT A10
SELECT trigger_name, table_name, status FROM user_triggers;TRIGGER_NA TABLE_NAME STATUS
---------- ---------- ------------------------------
ORDERS_BI ORDERS ENABLED
1 row selected.USER_TRIGGERS has ORDERS_BI on the same table ORDERS, ENABLED. This is the same trigger, so replacing it is the intended change.
CREATE OR REPLACE TRIGGER orders_bi BEFORE INSERT ON orders FOR EACH ROW
BEGIN
:NEW.created_at := NVL(:NEW.created_at, SYSDATE);
END;
/Trigger created.CREATE OR REPLACE TRIGGER replaced the body. The new logic (NVL(:NEW.created_at, SYSDATE)) kept the supplied date 2026-11-01.
INSERT INTO orders (order_id, amount, created_at) VALUES (1, 100, DATE '2026-11-01');
SELECT order_id, TO_CHAR(created_at, 'YYYY-MM-DD') AS created_at FROM orders;1 row created.
ORDER_ID CREATED_AT
---------- ----------
1 2026-11-01
1 row selected.02Trigger copied for another table with the same name
The trigger for ORDERS was copied to REFUNDS but the name TRG_SET_CREATED was left unchanged. Because trigger names are unique per schema, the new one cannot be created.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, created_at DATE);
CREATE TABLE refunds (refund_id NUMBER PRIMARY KEY, created_at DATE);
CREATE TRIGGER trg_set_created BEFORE INSERT ON orders FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/Table created.
Table created.
Trigger created.CREATE TRIGGER trg_set_created BEFORE INSERT ON refunds FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/CREATE TRIGGER trg_set_created BEFORE INSERT ON refunds FOR EACH ROW
*
ERROR at line 1:
ORA-04081: trigger 'TRG_SET_CREATED' already exists
Help: https://docs.oracle.com/error-help/db/ora-04081/COLUMN trigger_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT trigger_name, table_name FROM user_triggers;TRIGGER_NAME TABLE_NAME
---------------- ----------
TRG_SET_CREATED ORDERS
1 row selected.TRG_SET_CREATED already belongs to the ORDERS table. Replacing it would not help here: it is a trigger on a different table.
CREATE TRIGGER refunds_bi BEFORE INSERT ON refunds FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/Trigger created.Give the new trigger its own name (REFUNDS_BI). Both triggers now exist, one per table.
COLUMN trigger_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT trigger_name, table_name FROM user_triggers ORDER BY trigger_name;TRIGGER_NAME TABLE_NAME
---------------- ----------
REFUNDS_BI REFUNDS
TRG_SET_CREATED ORDERS
2 rows selected.FAQ
How do I avoid ORA-04081 in deployment scripts?
Use CREATE OR REPLACE TRIGGER for triggers you deploy repeatedly. It replaces the existing trigger with the new body.
Can two tables have triggers with the same name?
Not in the same schema. Trigger names are unique per schema, so a trigger on REFUNDS cannot reuse a name already used on ORDERS. Include the table name in the trigger name.
How do I find which table an existing trigger belongs to?
SELECT trigger_name, table_name, status FROM user_triggers; (or ALL_TRIGGERS with owner for other schemas).
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0