首页 > 数据库技术 > 详细

mysql 存储过程

时间:2018-11-14 00:33:31      阅读:211      评论:0      收藏:0      [点我收藏+]

存储过程:

  优势:1.较快执行速度(比单个的SQL语句快)

             2.调用时只需存储过程名和参数

  分类:1.系统存储过程:

        1.系统创建,有一些存储过程会在创建新的数据库时自动创建;

        2.名字以“sp_”开头

     2.自定义存储过程:

create proc | procedure pro_name
    [{@参数数据类型} [=默认值] [output],
     {@参数数据类型} [=默认值] [output],
     ....
    ]
as
    SQL_statements

  具体用法示例:

  1.创建不带参数存储过程:

--创建存储过程
if (exists (select * from sys.objects where name = ‘proc_get_student‘))
    drop proc proc_get_student
go
create proc proc_get_student
as
    select * from student;

--调用、执行存储过程
exec proc_get_student;

  2.创建带参存储过程:

--带参存储过程
if (object_id(‘proc_find_stu‘, ‘P‘) is not null)
    drop proc proc_find_stu
go
create proc proc_find_stu(@startId int, @endId int)
as
    select * from student where id between @startId and @endId
go

exec proc_find_stu 2, 4;

  3.修改存储过程:

--修改存储过程
alter proc proc_get_student
as
select * from student;

  

mysql 存储过程

原文:https://www.cnblogs.com/gaara-zhang/p/9955694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!