Summary of MySql Stored Procedure learning and mysql Stored Procedure

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.