Programmatic SQL Flashcards
1
Q
What is a procedure in MySQL?
A
A stored routine that has to be called in the SQL code
2
Q
What is a function in MySQL?
A
A stored routine that returns a value, it is not called and instead appears as or as part of an expression
3
Q
What is a trigger in MySQL?
A
A stored routine that takes place when a particular event occurs
4
Q
What is the syntax of a procedure?
A
CREATE PROCEDURE <proc-name> ( [IN|OUT|INOUT] <param-1> <type-1>, ... , [IN|OUT|INOUT] <param-n> <type-n> ) BEGIN [ DECLARE <var-name-1> <type-1>; ...] /*local variables*/ <body> /*SQL statements*/ END <delimiter-sym>
5
Q
What is the syntax of a function?
A
CREATE FUNCTION <func-name>( <param-1><type-1>, ... ,<param-n><type-n>) RETURNS <return-type> BEGIN [ DECLARE <var-name-1> <type-1>; ...] <body> RETURN <expression>; END <delimiter-sym>
6
Q
What is the syntax of a trigger?
A
CREATE TRIGGER <trigger-name> (BEFORE | AFTER) <event-type> ON <which-table> FOR EACH ROW BEGIN <block-of-actions> END