Stored procedures Flashcards
Cite a main problem with mixing sql code with say c#, java, or python production code?
If any of the tables or rows are changed that code will also have to be refactored. Use stored procedures instead
What is considered the ‘body’ of this stored procedure?
CREATE PROCEDURE get_clients()
BEGIN
SELECT * FROM clients
END
SELECT * FROM clients
What is the syntax for creating a stored procedure?
CREATE PROCEDURE named_procedure()
True or False
a single statement in a store procedure requires termination
True
DELIMITER $$
CREATE PROCEDURE get_clients()
BEGIN
select * from clients;
END$$
What is the purpose of the DELIMITER clause in sql?
DELIMITER $$
CREATE PROCEDURE get_clients()
BEGIN
select * from clients;
END$$
treats the entire stored procedure as a single unit
True or False
You can use anything as a DEMILITER (&&, **, $$, //)
True
but $$, // seems conventional
True or False
When executing a stored procedure, a resulting table is generated?
False
not in mysql
In myql what must be done to see any changes after creating a stored procedure?
must refresh the left workbench panel
What is the syntax for calling a stored procedure?
CALL named_procedure()
– Create a stored procedure called
– get_invoices_with_balance
– to return all the invoices with a balance > 0
DELIMITER $$
CREATE PROCEDURE get_invoices_with_balance()
BEGIN
select *
from invoices_with_balance
where balance > 0;
END$$
DELIMITER ;
True or False
When creating a view, stored procedure, trigger … it’s best practice to make sure the underlining query works as anticipated.
True, always do this!
True or False
Whenever you change the DELIMITER, you must change it back to it’s default value of?
True
DELIMITER ;
To create a stored procedure in mysql workbench all you have to do is?
Right-click stored procedure, create stored procedure.
When creating a store procedure in mysql through the workbench, you always have to adjust the delimiter.
No this is performed automatically in mysql workbench
Why does mysql use back ticks when naming a stored procedure? ie get_payments
To prevent naming clashes with sql keywords