Views, Stored Procedures, Functions, and Triggers: Download Mysql From This Link: Install
Views, Stored Procedures, Functions, and Triggers: Download Mysql From This Link: Install
• A stored procedure contains a sequence of SQL commands stored in the database catalog so
that it can be invoked later by a program
begin
-- execution code
end;
• out mode: allows you to pass value back from procedure to the calling program
• Suppose we want to keep track of the total salaries of employees working for each
department
Step 1: Change the delimiter (i.e., terminating character) of SQL statement from semicolon (;) to
something else (e.g., //)
So that you can distinguish between the semicolon of the SQL statements in the procedure and the
terminating character of the procedure definition
Step 2:
2. The body of the procedure is an SQL command to update the totalsalary column of the
deptsal table.
3. Terminate the procedure definition using the delimiter you had defined in step 1 (//)
returns <return_type>
Begin
-- execution code
end;
Example of Functions
SQL Triggers
• Examples:
• trigger-event {INSERT,DELETE,UPDATE}
• Create a trigger to update the total salary of a department when a new employee is hired:
• A trigger to update the total salary of a department when an employee tuple is modified:
SQL Triggers: An Example
• A trigger to update the total salary of a department when an employee tuple is deleted:
• To list all the triggers you have created: