Creating a SQL Anywhere Trigger

Create a SQL Anywhere trigger to enforce a referential integrity constraint in a SQL Anywhere database.

Prerequisites 

Before you can create a trigger, be sure the data server that contains the trigger is running, and you created and established a connection to the data server.

  1. Expand the Tables folder.
  2. Right-click the table to which to add the trigger, and select New > Trigger .

    The Create Trigger Skeleton page appears.

  3. Choose the SQL dialect you are using: Transact-SQL or Watcom-SQL.
  4. Enter the name of the trigger in the Name field.

    For example, titleInsert. Enter the Order Number if you are using Watcom SQL. The Order clause determines the order in which triggers of the same type ( insert, update, or delete) are fired.

  5. Enter an optional description in the Comments field, and click Next.
  6. In the Execution event handler field, select For update, For insert, or For delete to indicate the condition under which the trigger is to be invoked when the associated table is modified.
  7. If you are using Watcom SQL, you can select For Update Columns, and choose the check boxes of columns that you want updated when the trigger is invoked.
  8. If you are using Watcom SQL, click Next, and provide additional information for the trigger.
    Field Description
    Trigger level Specify the trigger isolation level as either Row level or Statement level.
    Trigger time Specify the trigger firing time as either Before or After the specified row or statement is altered or executed.
    Referencing Specify the data to be referenced:
    • New Row(s): If you have specified row-level isolation, the name you enter here refers to inserted row values after an update or insert. If you have specified statement-level isolation, the name you enter here refers to declared temporary tables holding the old and new values of the rows.
    • Old Row(s): If you have specified row-level isolation, the name you enter here refers to the values of a row before an update or delete. If you have specified statement-level isolation, the name you enter here refers to declared temporary tables holding the old and new values of the rows.
  9. Click Next, and specify save and execution properties for the trigger.
    Field Description
    Generate script Select this option to generate the script for the trigger.
    Enter or select the parent folder Specify an existing project or create a new project in which to save the SQL.
    File name Enter the name of the file in which to store the SQL.
    Execute immediately Execute the SQL immediately. If you do not select this option, you must complete execution of the SQL later to create the trigger.
    Open in editor after creation Create the trigger, and then open it in the Trigger Editor.
  10. Click Finish to create the trigger.

    The newly created trigger is opened automatically in the Trigger Editor.

Related concepts
Triggers
Related tasks
Creating an ASE Trigger
Editing a SQL Anywhere Trigger
Editing an ASE Trigger
Dropping a Trigger
Renaming a Trigger

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.