How to use storage structure in MySQL
In this issue, the editor will bring you about how to use the storage structure in MySQL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. Create two new data tables: student1 and student2
Create a new student1
DROP TABLE IF EXISTS student1;CREATE TABLE student1 (id INT NOT NULL auto_increment,name TEXT,age INT,PRIMARY KEY (id))
Create a new student2
DROP TABLE IF EXISTS student2;CREATE TABLE student2 (id INT NOT NULL auto_increment,name TEXT,age INT,PRIMARY KEY (id))
two。 Add data to student1
INSERT INTO student1 (name, age) VALUES ('xiaoming', 18); INSERT INTO student1 (name, age) VALUES (' xiaohong', 17); INSERT INTO student1 (name, age) VALUES ('xiaogang', 19); INSERT INTO student1 (name, age) VALUES (' xiaoyu', 18); INSERT INTO student1 (name, age) VALUES ('xiaohua', 20)
Implementation function description
1. Print some of the information in student1
two。 Copy part of the data from student1 to student2
3. Pass in parameters as restrictions to copy part of the data in student1 to student2
Matters needing attention
When writing a storage structure, we cannot end with a semicolon (;). Because our SQL statement ends with a semicolon (;). Here we want to modify the closing symbol (& &) of the storage structure.
Here we use DELIMITER in MySQL to modify it and change it to a semicolon (;) when the storage structure is created.
This is reflected in later examples. A similar situation is used in writing triggers for MySQL.
Mode of use
1. Print some of the information in student1
-DROP PROCEDURE IF EXISTS test_pro1 -DELIMITER & & CREATE PROCEDURE test_pro1 () BEGIN set @ sentence = 'select * from student1 where age