存储过程

来源:互联网 发布:淘宝达人是干嘛的 编辑:程序博客网 时间:2024/06/11 10:00
create database test 
use test 
create table student 

   id int primary key identity(1,1), 
   stuName varchar(20), 
   departID int, 
   totalScore int 

insert into student(stuName,departID,totalScore) values ('王五',1,88) 


select * from student 


select * from student where departID=1 


/* 简单存储过程*/ 
create procedure pro_student 
as 
select * from student where departID=1 
go 


exec pro_student 


/* 带输入参数的存储过程*/ 
create procedure pro_student1 
@departId int 
as 
  select * from student where departID=@departId 
go 
  
exec pro_student1 @departID=1 


/* 带输入输出参数的存储过程*/ 


create procedure pro_student2 
@departID int,@countNum int output 
as 
 set @countNum=(select count(*) from student where departID=@departID) 
print @countNum 


declare @departID int,@countNum int 
set @departID=1 
exec pro_student2 @departID,@countNum   
原创粉丝点击