CREATE EVENT Statement

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

Syntax

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

event-type:
   BackupEnd “Connect”  
     |  ConnectFailed  
     |  DatabaseStart 
     |  DBDiskSpace 
     |  “Disconnect” 
     |  GlobalAutoincrement 
     |  GrowDB  
     |  GrowLog  
     |  GrowTemp   
     |  IQMainDBSpaceFree  
     |  IQTempDBSpaceFree  
     |  LogDiskSpace  
     |  “RAISERROR”  
     |  ServerIdle  
     |  TempDiskSpace
trigger-condition:
   event_conditioncondition-name ) 
     { = 
       | < 
       | >!= 
       | <= 
       | >= }   value
schedule-spec:
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

Examples

Usage

Events can be used in two main ways:
  • Scheduling actions – the database server carries out a set of actions on a schedule of times. You can use this capability to schedule backups, validity checks, queries to fill up reporting tables, and so on.
  • Event handling actions – the database server carries out a set of actions when a predefined event occurs. The events that can be handled include disk space restrictions (when a disk fills beyond a specified percentage), when the server is idle, and so on.

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

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported by Adaptive Server Enterprise.

Permissions

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