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. In the Databases folder in Enterprise Explorer, under the database connection profile, expand the tree for a database, expand the Schemas folder and then the tree for the appropriate schema owner.
  2. Expand the Tables folder.
  3. Right-click the table to which to add the trigger, and select New > Trigger .
  4. Choose the SQL Dialect: Transact-SQL or Watcom-SQL.
  5. Enter the Name.

    For example, titleInsert.

  6. (Watcom-SQL only) Enter the Order Number.

    The Order clause determines the order in which triggers of the same type (insert, update, or delete) are fired.

  7. (Optional) Enter a description in the Comments field, and click Next.
  8. For Execution Event Handler, select For Update, For Insert, or For Delete to indicate the condition under which the trigger invokes when the associated table is modified.
  9. (Watcom-SQL only) Select For Update Columns, and select the columns that you want updated when the trigger is invoked.
  10. (Watcom-SQL only) 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 specify row-level isolation, the name you enter here refers to inserted row values after an update or insert. If you have specify 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 specify row-level isolation, the name you enter here refers to the values of a row before an update or delete. If you have specify statement-level isolation, the name you enter here refers to declared temporary tables holding the old and new values of the rows.
  11. Click Next and specify save and execution properties.
    Field Description
    Generate Script Generate a SQL file for the object.
    Enter or Select the Parent Folder Specify an existing project or create a new project in which to save the SQL file.
    File Name Enter the file name in which to store the SQL code.
    Execute Immediately Execute the SQL code immediately. If you do not select this option, you must complete execution of the SQL file later to create the object.
    Open in Editor After Creation Create the object and open it in its associated editor.
  12. 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

For product-related issues, contact Sybase Technical Support at 1-800-8SYBASE. Send your feedback on this help topic directly to Sybase Technical Publications: pubs@sybase.com