Mysql stored Process Learning Knowledge Summary _mysql

Source: Internet
Author: User
Tags mysql command line

What is a stored procedure:

Stored procedures can be said to be a recordset bar, it is a code block consisting of some T-SQL statements that implement functions like a method (check for additions or deletions to a single table or multiple tables), and then give the code block a name and call him when it comes to this feature.

Benefits of Stored procedures:

1. Because the database executes the action, it is compiled and executed first. However, the stored procedure is a compiled block of code, so the execution efficiency is higher than the T-SQL statement.

2. A stored procedure can replace a large number of T-SQL statements when the program interacts in the network, so it can also reduce the traffic of the network and increase the rate of communication.

3. The stored procedures enable users without permission to access the database indirectly under control, thereby ensuring data security.

Summary: In short, stored procedures are good things, in doing the project is an essential tool, the following describes the basic syntax of the stored procedure.

1. Stored Procedure Syntax

CREATE PROCEDURE proc_name ([in| Out| INOUT] param data type)
BEGIN
statement
end

Under the MySQL command line, each statement must be separated by a (semicolon), semicolon is a MySQL execution point, and the delimiter//command is used to convert the separator to//for the write stored procedure.

Delimiter//

2. Write a simple procedure

mysql-> CREATE PROCEDURE Hello ()
-> BEGIN
-> SELECT "Hello world!";
-> End
->//
Query OK, 0 rows Affected (0.00 sec)

1. Calling a stored procedure: Call Proc_name

Mysql-> call Hello ()//
+----------------------+
| It's a Hello world. |
+----------------------+
| It's a Hello world. |
+----------------------+
1 row in Set (0.00 sec)

2. Delete stored Procedures

DROP Proc_name

Note: You can call another stored procedure in one stored procedure, but you cannot delete it.

The above is a small set to introduce the MySQL stored process Learning knowledge Summary of the relevant knowledge, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.