1、存储过程的优点

①允许模块化程序设计

②执行速度更快

③减少网络流通量

④提高系统安全性

2、存储过程的分类

①系统存储过程

②用户自定义存储过程

3、常用的系统存储过程

SQL第六章(存储过程)

SQL第六章(存储过程)

 

SQL第六章(存储过程)

4、使用存储过程

①定义存储过程分语法

        created proc  存储过程名

         as

                 T- SQL语句

         go

 

 

②调用语法

      exec  过程名   【参数】

5、创建不带参数的存储过程

if exists(select*from sys.procedures where name='pr_stu_mark')
drop proc pr_stu_mark
go

create proc pr_stu_mark
as
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid

go

 

--查询存储过程
--exec dbo.存储过程名字
exec dbo.pr_stu_mark '李四'

 

6、创建带参数的存储过程

存储过程的参数分两种

    ①输入参数   用于想存储过程传入值,

    ②输出参数   用于在调用存储过程后,返回结果

if exists(select*from sys.procedures where name='pr_stu_mark')
drop proc pr_stu_mark
go

create proc pr_stu_mark(@name varchar(10)=null)
as
if @name is null
begin
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid
end
else
begin
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid and [email protected]
end

go

 

 

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-11-19
  • 2022-12-23
  • 2021-11-07
  • 2021-12-09
  • 2021-08-30
  • 2021-09-08
猜你喜欢
  • 2021-04-18
  • 2021-12-05
  • 2021-12-29
  • 2021-12-28
  • 2021-10-01
  • 2022-02-12
相关资源
相似解决方案