ITZone

Use triggers in SQL via basic examples

What is a trigger?

Simply put, the trigger is a stored procedure with no parameters. The trigger executes automatically when one of the three Insert, Update and Delete statements changes the data on the trigger table. ?

Trigger’s syntax

What does trigger use?

Problem set.

Solution

Problem

  1. The initial set amount = 5 then increases to 10 => the number in stock will decrease by 10 respectively
  2. The number placed at this time = 10 then reduced to 3 => the number in stock will increase by 7 respectively

Problem solving

Maybe you want to see:

Optimize WHERE statements in MySQL
Introducing LevelDB and comparing performance with MySQL

Follow the small example

  1. Initially add data and select it ?

  1. Order 5 products with code 1

  1. Update to 10

  1. Update on 3

  1. Update some other information that is not related to quantity

  1. Delete orders

Source code all ?

  1. Additional trigger

  1. Trigger Delete

  1. Trigger Edit


Conclude

The thing that you use Trigger is not mandatory and we often think that no one uses it completely wrong ?. But Trigger, as far as I know, there are still many places that will use it for their own purposes.

Thanks for reading.

Filter customer Insights with data – the decision maker’s decision factor
Use triggers in SQL via basic examples

Analyzing Northern lottery data ”]

Share the news now