Databases Reference
In-Depth Information
VARCHAR(25), IN param_pages INT, OUT param_message VARCHAR(100))
BEGIN
IF param_pages > 100 THEN
SET param_message = 'the number of pages is too big';
ELSE
UPDATE book SET page_count = page_count + param_pages WHERE
isbn=param_isbn;
SET param_message = 'success';
END IF;
END$$
--
-- Functions
--
CREATE DEFINER=`marc`@`%` FUNCTION `get_country_name`
(param_country_code CHAR(2)) RETURNS varchar(50) CHARSET latin1
READS SQL DATA
BEGIN
DECLARE var_country_name VARCHAR(50) DEFAULT 'not found';
SELECT description into var_country_name FROM country WHERE
code = param_country_code;
RETURN var_country_name;
END$$
DELIMITER ;
Executing code with triggers
Triggers are code that we associate with a table to be executed when certain actions
occur, for example, after a new INSERT statement in the book table. The action does
not need to happen within phpMyAdmin.
Contrary to routines that are related to an entire database and are visible on the
database's Structure page, triggers for each table are accessed from this specific
table's Structure page.
Prior to MySQL 5.1.6, we needed the SUPER privilege to create and
delete triggers. In version 5.1.6, a TRIGGER table-level privilege was
added to the privilege system. Hence, a user no longer needs the
powerful SUPER privilege for these tasks.
In order to perform the following exercise, we will need a new INT column— total_
page_count —in our author table.
 
Search WWH ::




Custom Search