Triggers are SQL statements or a set of SQL statements which is stored to be activated when an event associating with a database table occurs. The events can be one of following:
Delete - the trigger is activated if something is deleted from the table.
Insert - the trigger is activated if something is inserted into the table .
Update - the trigger is activated if the table is updated.
To create a trigger you can use the 'CREATE TRIGGER' statement. Here is the syntax:
CREATE TRIGGER trigger_name BEFORE [table event] FOR EACH ROW [sql statements];
For better use of triggers you can use the DELIMETER function to enable adding of sequence of mysql events.
STORED PROCEDURES
Stored procedures are blocks of code stored on the server and will normally carry out a
series of SQL statements. They are segments
of declarative SQL code, which and can be invoked by a program, a trigger or even another stored procedure.
To create a stored procedure you will need to use the 'CREATE PROCEDURE' statement. For better creation of a stored procedure, you can also usee the DELIMETER function to enable adding of sequence of mysql statements. Here is the syntax:
DELIMETER //
CREATE PROCEDURE procedurename()
BEGIN
[SQL statements]
END //
DELIMETER;
In order to call or invoke the stored procedure, you can use the following command:
CALL procedurename();
To create a stored procedure you will need to use the 'CREATE PROCEDURE' statement. For better creation of a stored procedure, you can also usee the DELIMETER function to enable adding of sequence of mysql statements. Here is the syntax:
DELIMETER //
CREATE PROCEDURE procedurename()
BEGIN
[SQL statements]
END //
DELIMETER;
In order to call or invoke the stored procedure, you can use the following command:
CALL procedurename();
No comments:
Post a Comment