In this lesson, you will learn how to use Sybase WorkSpace to create a new trigger for an Adaptive Server Enterprise server database table. �
If necessary, select Window|Open Perspective|Database Development from the main menu bar to open the Database Development perspective.
In the Database Explorer view, expand the Tables folder under the sample pubs database that you installed during the tutorial setup process.
Triggers reside with their corresponding table.
In the Database Explorer view, right-click the titles table and select New|Trigger.
The Create Trigger Skeleton wizard displays.
In the Name field,
enter insert_title
.
Click the For insert check box.
Optionally, you can add a comment. Sybase WorkSpace updates the trigger code in the Preview box as you enter data.
Click Finish.
The SQL Editor creates and displays a skeleton of the trigger so that you can finish it and then save it to the server.
Add the following SQL statements to the trigger after the begin statement.
/*� * We are not allowing any inserts just for � * illustration purposes.� */� if (select count(*) from inserted) >0� begin� rollback transaction� raiserror 99999 "We are not allowed to insert anything into the titles table."� end
In this example, the SQL code indicates to display an error message if any user tries to insert data into the titles table. Format your code in the SQL Editor to look like the following example.
Right-click anywhere in the SQL Editor window and select Save to Server to save your changes.
You will use this trigger in subsequent tutorials.
Select File|Close on the main menu bar to close the SQL Editor.
You can easily make changes to the trigger and save it back to the server.