T-SQL에는 매개 변수 저장 프로세스의 생성과 실행이 있다

7600 단어
 1 use StudentManager
 2 go
 3 if exists(select * from sysobjects where name='usp_ScoreQuery2')
 4 drop procedure usp_ScoreQuery2
 5 go
 6 --          
 7 create procedure usp_ScoreQuery2 
 8 @CSharp int,
 9 @DB int
10 as
11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
12     from Students
13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
14     where CSharp<@CSharp or SQLServerDB<@DB
15 go
16 --          
17 exec usp_ScoreQuery2 60,65 --        
18 exec usp_ScoreQuery2 @DB=65,@CSharp=60 --        

매개변수에 기본값 지정하기
 1 use StudentManager
 2 go
 3 if exists(select * from sysobjects where name='usp_ScoreQuery3')
 4 drop procedure usp_ScoreQuery3
 5 go
 6 --          
 7 create procedure usp_ScoreQuery3 
 8 @CSharp int=60,
 9 @DB int=60
10 as
11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
12     from Students
13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
14     where CSharp<@CSharp or SQLServerDB<@DB
15 go
16 --          
17 exec usp_ScoreQuery3 65 --
18 exec usp_ScoreQuery3 @DB=65
19 exec usp_ScoreQuery3 default,65 --         
20 exec usp_ScoreQuery3   --           

 
전재 대상:https://www.cnblogs.com/Spinoza/p/10051258.html

좋은 웹페이지 즐겨찾기