Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statement-level triggers for INSERT, UPDATE, DELETE [CORE1268] #1690

Open
firebird-automations opened this issue May 17, 2007 · 7 comments
Open

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Igor Lobov (ivl)

Votes: 4

Create a way to create statement-level triggers for INSERT, UPDATE and DELETE, which executing once, not for each row .

@firebird-automations
Copy link
Collaborator Author

Modified by: Igor Lobov (ivl)

description: Create a way to create statement-level triggers for INSERT, UPDATE and DELETE, which executing ?nce, not for each row .

=>

Create a way to create statement-level triggers for INSERT, UPDATE and DELETE, which executing once, not for each row .

@firebird-automations
Copy link
Collaborator Author

Modified by: Igor Lobov (ivl)

Component: Engine [ 10000 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

How and for what you would use it?

@firebird-automations
Copy link
Collaborator Author

Commented by: Igor Lobov (ivl)

I have three cases:

1. We could use statement-level triggers for log operations when we need to register just only fact (user name, date and time or/and duration) of operator execution (INSERT, DELETE or UPDATE).
2. We could use it for permissibility checkup of usage such operators for cases with long duration or/and with using UDF (witch check external factors).
3. We could use it for some renumbering operations when we need to use continuous sequences.
We have two tables:
CREATE Table1 (
Id INTEGER NOT NULL,
Field1 <type>,
.....
CONSTRAINT PK_TABLE1 PRIMARY KEY (Id)
);

CREATE Table2 (
Id_Table1 INTEGER NOT NULL,
Continuous_sequence_field INTEGER NOT NULL,
........
CONSTRAINT FK_TABLE2_TABLE1 FOREIGN KEY (Id_Table1) REFERENCES Table1 (Id)
);

In field 'Continuous_sequence_field' I want to have continuous sequence.
If I delete some records from Table1 continuous sequence in Table2 would be corrupted.
I would make renumbering in statement-level trigger (AFTER DELETE).

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 12131 ] => Firebird [ 14811 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Bernardo Signori (bernardo)

This should be the default behaviour according to the sql standard. The sql standard has an optional clause "for each row" that makes the trigger execute once for each row affected by the statement (the current Firebird behaviour).
Changing the default behaviour of Firebird is obviously not possible but it would be very valuable if this could be added.
Perhaps the optional clause could be [FOR EACH ROW | FOR ALL ROWS]. And add to the documentation that the default is "for each row".
Also the row_count variable could hold the number of affected rows.

@firebird-automations
Copy link
Collaborator Author

Commented by: Ain Valtin (ain)

There is ticket for making create trigger syntax compliant with SQL2003 (CORE711) which is marked as fixed in FB2.1, but unfortunately it only addresses the placement of the table name part of the syntax, not FOR EACH {ROW | STATEMENT} part :(
The current FB behaviour of FOR EACH ROW is sometimes real PITA...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant