CREATE EVENT Statement

Defines an event and its associated handler for automating predefined actions. Also defines scheduled actions.

Quick Links:

Go to Parameters

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

CREATE EVENT event-nameTYPE event-type
       [ WHERE trigger-conditionAND trigger-condition ], ...]
       | SCHEDULE schedule-spec, … ]
   …[ ENABLE | DISABLE ]
   …[ ATCONSOLIDATED | REMOTE | ALL } ]
   …[ HANDLER
      BEGINEND ]

event-type - (back to Syntax)
   BackupEnd“Connect”  
     |  ConnectFailed 
     |  DatabaseStart 
     |  DBDiskSpace 
     |  “Disconnect” 
     |  GlobalAutoincrement 
     |  GrowDB 
     |  GrowLog 
     |  GrowTemp   
     |  IQMainDBSpaceFree 
     |  IQTempDBSpaceFree 
     |  LogDiskSpace 
     |  “RAISERROR” 
     |  ServerIdle 
     |  TempDiskSpace

trigger-condition - (back to Syntax)
   event_conditioncondition-name ) 
     { = 
       | < 
       | >!= 
       | <= 
       | >= }  value

schedule-spec - (back to Syntax)
schedule-name ] 
     { START TIME start-time | BETWEEN start-time AND end-time } 
     [ EVERY periodHOURS  |  MINUTES  | SECONDS } ] 
     [ ON { ( day-of-week, … ) | ( day-of-month, … ) } ] 
     [ START DATE start-date ]

Parameters

(back to top)

Examples

(back to top)

Usage

(back to top)

An event definition includes two distinct pieces. The trigger condition can be an occurrence, such as a disk filling up beyond a defined threshold. A schedule is a set of times, each of which acts as a trigger condition. When a trigger condition is satisfied, the event handler executes. The event handler includes one or more actions specified inside a compound statement (BEGIN... END).

If no trigger condition or schedule specification is supplied, only an explicit TRIGGER EVENT statement can trigger the event. During development, you might want to develop and test event handlers using TRIGGER EVENT and add the schedule or WHERE clause once testing is complete.

Event errors are logged to the database server console.

When event handlers are triggered, the server makes context information, such as the connection ID that caused the event to be triggered, available to the event handler using the EVENT_PARAMETER function.

Note: Although statements that return result sets are disallowed in events, you can allow an event to call a stored procedure and insert the procedure results into a temporary table.
Side Effects:
  • Automatic commit.
  • The actions of an event handler are committed if no error is detected during execution, and rolled back if errors are detected.

Standards

(back to top)

  • SQL—Vendor extension to ISO/ANSI SQL grammar.
  • SAP Sybase Database product—Not supported by Adaptive Server.

Permissions

(back to top)

Requires one of:
  • MANAGE ANY EVENT system privilege.
  • CREATE ANY OBJECT system privilege.

Event handlers execute on a separate connection, with the privileges of the event owner. To execute with privileges other than MANAGE ANY EVENT system privilege, you can call a procedure from within the event handler: the procedure executes with the permissions of its owner. The separate connection does not count towards the ten-connection limit of the personal database server.

Related reference
ALTER EVENT Statement
BEGIN … END Statement
COMMENT Statement
DROP Statement
TRIGGER EVENT Statement