0% found this document useful (0 votes)
57 views2 pages

Trigger

The document discusses implicit NEW and OLD variables that are available in row-level triggers. The NEW variable refers to the affected column after an event, while the OLD variable refers to the column before the event. A table shows when NEW and OLD variables are available depending on the database operation and timing of the trigger. For example, on a DELETE, the NEW variable is not available but the OLD variable is available in an AFTER trigger.

Uploaded by

siva86
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views2 pages

Trigger

The document discusses implicit NEW and OLD variables that are available in row-level triggers. The NEW variable refers to the affected column after an event, while the OLD variable refers to the column before the event. A table shows when NEW and OLD variables are available depending on the database operation and timing of the trigger. For example, on a DELETE, the NEW variable is not available but the OLD variable is available in an AFTER trigger.

Uploaded by

siva86
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NEW and OLD implicit variables in rowlevel triggers

In addition to the local variables declared in the trigger, row-level triggers have access to implicit variables whose values are automatically set by the system. The OLD variable refers to the value of a column before the incident occurs; the NEW variable refers to a column affected by the incident, after it has occurred. You can use expressions to read from and assign values to row variables. Certain operations on the NEW or OLD row variables may not be accessible or modifiable depending on the type of modification. For example, if the ObjectServer deletes a row, there is no NEW row to read or modify. The following table shows when the NEW and OLD variables are available depending on the database operation. Table 1. Availability of special row variables Operation Timing mode BEFORE AFTER BEFORE AFTER BEFORE AFTER Is the NEW variable available? Y Y Y Y N N Y Y Y N Y N N N N N Is the NEW variable modifiable? N N Y N Y Y Y N Is the OLD variable available? N N N N N N Y N Is the OLD variable modifiable?

INSERT INSERT UPDATE UPDATE DELETE DELETE

REINSERT BEFORE REINSERT AFTER

Note: In a post-reinsert trigger, only the NEW variable is available, and this represents the data from the INSERT statement. For example, if Tally is not specified in the INSERT statement, new.Tally will have a default value of 0 (zero).

Example
The following database trigger uses the NEW variable to update the StateChange column when a row in the alerts.status table is modified to time stamp the change.

create trigger SetStateChange group default_triggers priority 1 before update on alerts.status for each row begin set new.StateChange = getdate; end;

Parent topic: Creating database triggers (CREATE TRIGGER command)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy