Database System Experiment 8 SQL language - the basic storage process

Experiment 8 SQL database language - the basic storage process

One. lab environment:

​ MYSQL WORKBENCH

two. Experimental content and achievement:

(Question given by the corresponding SQL statement and the execution result, to be able to copy the SQL statement, the experimental results theme; Title content without copying)

Proceed on the basis of experiments before, it had been established before the experiment related jxgl database.

Do the following in the learning management system (jxgl) in:

View and use jxgl database:

use jxgl;
show tables;

Here Insert Picture Description
1. Definitions of parameters with the stored procedure. Create a name in the database for InsRecToC jxgl stored procedure, a function of the stored procedure to insert a new record to the course, the value provided by the newly recorded parameters, execute the stored procedure.

delimiter //
create procedure InsRecToC(in the_cno char(2),in the_cname varchar(20),in the_cpno char(2),in the_ccredit int(11))
Begin
insert into course value(the_cno,the_cname,the_cpno,the_ccredit);
End;

Run will see the completion of the procedure to create success, and on the left you can see the procedure already exists;

the implementation of the process:

call InsRecToC("15","数据库实验",null,1);

Execute select statement inserted in the data view shows success:
Here Insert Picture Description

2. Create a name for select_s stored procedure, function of the stored procedure is to query information about all the girls from the student table and execute the stored procedure

delimiter //
create procedure select_s()
Begin
select * from student where ssex="女";
End;

Perform this procedure:

call select_s();

Here Insert Picture Description
3. Define a storage procedure parameters. Create a name for insrectos stored procedure, function of the stored procedure is a query of a student's name and age of the student based on student number from the table and returns. Execute the stored procedure

delimiter //
create procedure insrectos (in sn char(7),out age int,out the_name varchar(20))
begin 
    select sage,sname into age,the_name 
    from student
    where sno = sn;
end//

Call the stored procedure:

delimiter ;
set @age = 0, @sno ="2005002",@the_name = "no_name"; #设初始变量为'2005002',0,'no_name'
call insrectos (@sno,@age,@the_name); #调用存储过程
select @the_name,@age;  #显示the_name和age


4. The stored procedure select_s renamed SELECT_STUDENT

// Check the official documentation should be seen now is no longer supported operations sp_rename

// So here I used directly to build a new table and then delete the old content is consistent operating table

delimiter //
create procedure SELECT_STUDENT()   #创建新表,内容相同,名称不同
Begin
select * from student where ssex="女";
End//
drop procedure select_s;  #删除旧表


5. Delete stored procedure insrectos

drop procedure if exists insrectos;

You can see deleted successfully:

6. View the source code to build stored procedures

See all of the stored procedure:

Show procedure status;

Here Insert Picture Description
View a particular stored procedure:

show create procedure SELECT_STUDENT;
Published 68 original articles · won praise 36 · views 10000 +

Guess you like

Origin blog.csdn.net/dingdingdodo/article/details/103016469