Вы находитесь на странице: 1из 4

PRAKTIKUM BASIS DATA - MODULE 4

STORE
PROCEDURE &
TRIGGER
ENTERPRISE SYSTEM ENGINEERING
LABORATORY

2018/2019
Telkom University
I. Store Procedure Store Procedure Structure on
Store procedure are programs SQL server:
created and stored in a MySQL
database. Procedures stored in the a. Create Procedure
database can be equated with the
object-oriented approach in
programming and can control
database access.

The advantages of Store


procedure: Create : to create a new procedure,
when creating procedure the schema
 Quickly, the reading of a
name usually needs or does not need
program can be done in the
to be filled (may be empty).
database (pre-compilation)
 Parameters : are optional because
thereby reducing taffic.
when executed the parameters here
Simple, the separation between
must have a condition where in
the acces logic database with the
(sql_statement) has parameters that
logic program so the program
can later be called upon calling
will be simpler.
parameters.
Portable, the database will be
Definer : If Definer is specified, the
accessed anywhere.
procedure is executed with certain
properties or not.
Select : to start the procedure.
From : for Reference Procedure.
Where : to sort data in the Select
command.
Store Procedure Structure on
The advantages of Trigger:
SQL server:
Facilitate data validation.
b. Execute Procedure
Auditing data changes in the
database.
Provide an alternative way to
CALL : to execute an existing check integrity.
procedure.

c. Deleting Procedure There are 3 times for an


activated trigger
(Trigger Timing):
DROP : to remove procedure Before Trigger. The trigger
that has been made. database which will be executed
before the query statement is
completed in the execution. This
II. Trigger type is generally used to obtain
a particular column value
Trigger is a SQL statement
before completing an insert or
that is in the database and
update statement.
must be stored when there is
For / After Trigger. The trigger
an event that occurs in a
database which will be executed
database table. Differences
after the query statement is
Trigger with Store Procedure
completed in the execution.
is trigger is activated
Instead-Of Trigger. The trigger
implicitly when an event
database which will be executed
occurs in the database table,
replaces a query statement.
while the procedure is called
explicitly. The event in
question is trigger types that
are DML statements (Insert,
Update and Delete), DDL
statements (create, Drop,
and Alter), and database
operations.
Table-name: the name of the
Structure of Trigger on SQL
table to which we will execute.
server: BEFORE / AFTER / INSTEAD
a. Creating Trigger OF : determines whether the
trigger we want to use timing
before (BEFORE) or after
(AFTER) or replace (INSTEAD
OF).
INSERT / UPDATE / DELETE :
specifying the trigger we want
CREATE / ALTER Trigger : Used to give will be executed after
to create a new trigger (CREATE) or replace the statement
trigger or alter (ALTER) trigger (INSERT, UPDATE & DELETE)
trigger-name : trigger name that INSERT INTO VALUES : add
we will create or change. new data in the database
ON : Used to select the table we table.
want to trigger.
b. Removing Trigger.

DROP trigger : Used to remove


triggers that has been made.

Вам также может понравиться