I am stuggling to create a trigger that drops a constraint using ALTER TABLE I have read that this command cannot be used within a trigger so have included it as a string. All the code has been tested outside of a trigger and works correctly, any help would be appreciated.
The error I am currently getting is 'commit rollback not alowed within atomic operation'
CREATE TRIGGER updates_equipment_type BEFORE INSERT ON trained_on REFERENCING NEW AS new_trained_on FOR EACH ROW WHEN (new_trained_on.type NOT IN (SELECT type FROM equipment_type)) BEGIN EXECUTE IMMEDIATE 'ALTER TABLE trained_on DROP CONSTRAINT relationship_fixed_by ALTER TABLE equipment_type DROP CONSTRAINT mandatory_participation_in_fixed_by'; INSERT INTO equipment_type VALUES (new_trained_on.type); EXECUTE IMMEDIATE 'ALTER TABLE trained_on ADD CONSTRAINT relationship_fixed_by FOREIGN KEY (type) REFERENCES equipment_type ALTER TABLE equipment_type ADD CONSTRAINT mandatory_participation_in_fixed_by CHECK (type IN ( SELECT type FROM trained_on))'; END
Request clarification before answering.
Not being able to ALTER a table is not just a syntax issue, it is a semantic one: you cannot execute a COMMIT from within a trigger execution, and an ALTER implies a COMMIT. So, the EXECUTE IMMEDIATE does not help, it's still "within the trigger execution".
Do not confuse "TRIGGER EVENT" with CREATE TRIGGER, they don't have anything to do with one another.
The CREATE EVENT needs a name, but no schedule or condition, because you are going to use an explicit TRIGGER EVENT.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.