Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add triggers in AndoridSQLite database development

Shulou Source: shulou.com Published: 2022-06-02 10:27:15 10月04日 Update

AndoridSQLite database development how to add triggers, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Add triggers for AndoridSQLite database development

A TRIGGER is an action triggered by an event. These events include INSERT, DELETE, UPDATE, and UPDATE OF. When the database system executes these events, it is activated and triggered to perform the corresponding action. Let's add triggers for the database. The steps are as follows:

(1) Open the database, click the gear button in the lower left corner, select the Create Trigger option, and pop up the Trigger Creator dialog box, as shown in figure 1.23.

Figure 1.23 Trigger Creator dialog box

(2) enter the name of the trigger, such as ScoreTrigger, in the Trigger name: text box. Select the trigger time in the WHEN list box. There are three times, Before, After, and Instead Of. After is selected here. Select the event that triggers the trigger in the Database event list box. There are four kinds of events, INSERT, DELETE, UPDATE, and UPDATE OF. INSERT is selected here. The Table list box sets the table to which triggers are added, such as the Students table. Then write the trigger action in the text field that contains the prompt write your tigger action here, with the following code:

FOR EACH ROWWHEN (Sales) > = 1BEGINupdate Students set Score = Sales * .15

The effect in the add trigger dialog box is shown in figure 1.24.

Figure 1.24 Trigger Creator dialog box

(3) after clicking the Save button, exit the add trigger dialog box. At this point, a trigger named ScoreTrigger is added to the specified database, as shown in figure 1.25.

Figure 1.25 ScoreTrigger trigger

Note: the ScoreTrigger trigger added here will trigger when the data is inserted.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Triggers data databases events dialogs dialogs selections such as figure development button time not for help clarity code information content action name for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Docker vpn MariaDB