Summary of MySql Stored Procedure learning and mysql Stored Procedure
What is a stored procedure:
Stored procedures can be said to be a record set, it is a code block composed of some T-SQL statements, these T-SQL statement code implements some functionality like a method (add, delete, modify, and query a single table or multiple tables), and then give the code block a name, you can call this function when using this function.
Advantages of stored procedures:
1. Because the database first compiles and then executes the action. However, the stored procedure is a compiled code block, so the execution efficiency is higher than the T-SQL statement.
2. A stored procedure can replace the large pile of T-SQL statements when the program interacts in the network, so it can also reduce the network traffic and improve the communication rate.
3. stored procedures allow unauthorized users to indirectly access the database under control to ensure data security.
Summary: stored procedures are good things. They are essential tools for projects. The following describes the basic syntax of stored procedures.
1. Stored Procedure syntax
Create procedure proc_name ([IN | OUT | INOUT] param data type) BEGINstatementEND
In the mysql command line, each statement must be separated by a semicolon (semicolon), which is the execution point of mysql. In order to write the stored procedure, use the delimiter // command to convert the separator //.
Delimiter //
2. Write a simple procedure
mysql-> CREATE PROCEDURE hello()-> BEGIN-> SELECT "Hello World!";-> END-> //Query OK, 0 rows affected (0.00 sec)
1. call the stored procedure: call proc_name
mysql-> CALL hello()//+----------------------+| it is a hello world. |+----------------------+| it is a hello world. |+----------------------+1 row in set (0.00 sec)
2. delete a stored procedure
DROP proc_name
Note: A stored procedure can call another stored procedure, but cannot be deleted.
The above is a summary of MySql Stored Procedure learning. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!