Continuing my series on how same things can be done differently in SQL Server and MySQL, in this post, we will see how Stored Procedures are supported in both SQL Server and MySQL. We also explore the difference in calling them.
Consider the following code assuming that you have a database named test
Create procedure proc_test
select 'Hello World from SQL Server'
The above code creates a stored procedure named proc_test in your database. To execute the procedure, you need to use either EXEC or EXECUTE keywords
This statement will display the result Hello World in SQL Server
DROP PROCEDURE IF EXISTS `test`.`proc_test`$$
CREATE PROCEDURE `test`.`proc_test` ()
select 'Hello World from MySQL' as message;
The above code creates a stored procedure named proc_test in the database named test. To execute the procedure, you need to use the keyword CALL
which will display the result Hello World in MySQL.
Note that in MySQL, delimiters are important for creating a stored procedure and the procedure name should be succeed by empty brackets () if there are no parameters.
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|