SQL SERVER 之存储过程(创建、修改、删除、执行) 您所在的位置:网站首页 sql语句删除一条记录的命令是 SQL SERVER 之存储过程(创建、修改、删除、执行)

SQL SERVER 之存储过程(创建、修改、删除、执行)

2023-10-01 17:40| 来源: 网络整理| 查看: 265

我就不写一堆原理,书上基本原理肯定是有的。直接用代码,简单粗暴。

创建、修改存储过程格式:

CREATE / ALTER PROCEDURE procedure_name @parameter data_type,--输入参数 @parameter data_type OUTPUT --输出参数 AS Begin SQL 语句 End

例如:

/*创建存储过程*/ create procedure GetStudentAvgAndCount @StuClass nvarchar(30), @StuSex nvarchar(10), @StuCount int output as begin if(@StuClass is not null and @StuClass '') begin select st.Sclass, sc.Scourse, avg(sc.Sscore) courseAvg from tb_student st,tb_score sc where st.Sclass = @StuClass and st.Sno = sc.Sno group by st.Sclass,sc.Scourse set @StuCount = (select count(*) from tb_student st where st.Sclass = @StuClass and st.Ssex = @StuSex) end else begin set @StuCount = 0 end end

删除存储过程格式:

DROP PROCEDURE procedure_name

例如:

DORP PROCEDURE GetStudentAvgAndCount

执行存储过程

/*执行存储过程*/ declare @StuMaleCount int exec GetStudentAvgAndCount '一班','男', @StuMaleCount output select @StuMaleCount StuMaleCount

运行结果



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有