Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 (Français) » SQL Anywhere Server - SQL Usage » Stored procedures and triggers » Using procedures, triggers, and batches » Introduction to triggers

 

Creating triggers

You create triggers using either Sybase Central or Interactive SQL. In Sybase Central, you can use a wizard to provide necessary information. In Interactive SQL, you can use a CREATE TRIGGER statement. For both tools, you must have DBA or RESOURCE authority to create a trigger and you must have ALTER permissions on the table associated with the trigger.

The body of a trigger consists of a compound statement: a set of semicolon-delimited SQL statements bracketed by a BEGIN and an END statement.

You cannot use COMMIT and ROLLBACK and some ROLLBACK TO SAVEPOINT statements within a trigger.

 ♦  To create a trigger for a given table (Sybase Central)
  1. Use the SQL Anywhere 12 plug-in to connect to the database as a user with DBA or Resource authority.

  2. In the left pane, click Triggers.

  3. Choose File » New » Trigger.

  4. Follow the instructions in the Create Trigger Wizard.

  5. To complete the code, in the right pane click the SQL tab.

 ♦  To create a trigger for a given table (SQL)
  1. Connect to a database as a user with DBA authority. You must also have ALTER permissions on the table associated with the trigger.

  2. Execute a CREATE TRIGGER statement.

 Example 1: A row-level INSERT trigger
 Example 2: A row-level DELETE trigger example
 Example 3: A statement-level UPDATE trigger example
 See also