AndoridSQLite database development based tutorial (10)

AndoridSQLite database development based tutorial (10)

Add Trigger

Trigger (TRIGGER) is an event to trigger some action. These events include INSERT, DELETE, UPDATE, and UPDATE OF. When the database system to perform these events, it will activate the trigger appropriate action. Add the following triggers for the database. Steps are as follows:

(1) open database, click gear bottom left button, select the Create Trigger option Trigger Creator pop-up dialog box shown in Figure 1.23.

 

Figure 1.23 Trigger Creator dialog box

(2) Trigger name: the name of the trigger text box, such as ScoreTrigger. Select WHEN trigger time trigger in the list box. There are three times, respectively, Before, After and Instead Of. Here is a selection of After. Select the trigger event triggers in the Database event list box. There are four events, namely, INSERT, DELETE, UPDATE, and UPDATE OF. Here is a selection of INSERT. Table list box is set to add the trigger table, as Students table. Then containing message write your tigger action here in the text field write trigger action, code written as follows:

FOR EACH ROW

WHEN (Sales) >= 1

BEGIN

update Students set Score = Sales * .15;

END

The Add Trigger dialog 1.24 effects shown in FIG.

 

Figure 1.24 Trigger Creator dialog box

(3) After you click the Save button to exit the Add Trigger dialog box. In this case, a trigger is called ScoreTrigger is added to the specified database, as shown in 1.25.

 

Figure 1.25 ScoreTrigger trigger

Note: This add ScoreTrigger trigger fires when inserting data.

Guess you like

Origin www.cnblogs.com/daxueba-ITdaren/p/11780918.html