Getting started with MySQL's stored procedures and practices

Source: Internet
Author: User

The stored procedures are:
Through a series of SQL statements, according to the parameters passed in (also can not), through a simple call,
The ability to complete more complex functions than a single SQL statement, stored on the database server side, only need to compile once and then reuse no need to compile again. The main control of the stored process.

A transaction is a series of data change operations that comprise a whole. Once a transaction contains an operation that fails or the user aborts, the user can control all operations in the transaction body to be undone, returning the state before the transaction begins.
The operation in a transaction is a whole, either whole or not. Thus ensuring the integrity of the data.
In MySQL, the MyISAM storage engine does not support transactions, INNODB support.

Both are very important knowledge in the database.

One, stored procedures

Create a stored procedure for the Test1 table mysql> delimiter $--delimiter $ is set to the command termination symbol, in place of the default semicolon, because the semicolon has other uses .mysql> CREATE PROCEDURE Sp_test1 ()  -Begin-> CREATE TABLE test1 (ID int,name varchar);->insert into test1 values (1, ' Lilei ');-> select * FROM Test1;-> end-> $Query OK, 0 rows Affected (0.00 sec) mysql> delimiter; The recovery semicolon is called as a delimited terminating symbol for calling the stored procedure mysql> call Sp_test1 (); Creating a stored procedure with parameters mysql> delimiter $--delimiter $ is set to the command termination symbol, in place of the default semicolon, Because semicolons have other uses .mysql> CREATE PROCEDURE sp_test (in pi_id int, out po_name varchar ()), begin-> select * from Test.tb_ Test;-> Select Tb_test.name to Po_name from test.tb_test where tb_test.id = pi_id;-> end-> $Query OK, 0 rows AF Fected (0.00 sec) mysql> delimiter; --Recover semicolon as delimited terminating symbol 5. Call the stored procedure mysql> set @po_name = '; Query OK, 0 rows Affected (0.00 sec) Mysql> Call Sp_test (1, @po_name);

  

Second, things

Getting started with MySQL stored procedures and practices

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.