SQLServer --自定义带输入参数的存储过程

带输入参数的存储过程

SQLServer --自定义带输入参数的存储过程_第1张图片

SQLServer --自定义带输入参数的存储过程_第2张图片


在参数中添加默认值

SQLServer --自定义带输入参数的存储过程_第3张图片

SQLServer --自定义带输入参数的存储过程_第4张图片

use StuManageDB
go

if exists(select * from sysobjects where name='usp_ScoreQuery1')
drop procedure usp_ScoreQuery1
go

create procedure usp_ScoreQuery1
--参数自定义默认值
@CSharp int=60,@DB int=60

as
    select Students.StudentId,StudentName,CSharp,SQLServerDB
    from Students
    inner join ScoreList on Students.StudentId = ScoreList.StudentId
    where CSharp<@CSharp or SQLServerDB<@DB

go

--四种调用方式
exec usp_ScoreQuery1  --俩个参数都使用默认值
exec usp_ScoreQuery1 @DB=80 --第二个参数没有赋值,则默认
exec usp_ScoreQuery1 default,80 --不使用显示方式赋值
exec usp_ScoreQuery1 80

你可能感兴趣的:(SQLServer高级开发技能,SQL)