首页 > 代码库 > SQLServer存储过程
SQLServer存储过程
--无参数存储过程创建和调用
--创建存储过程usp_testusergoif exists(select * from sysobjects where name=‘usp_test‘)drop proc usp_testgocreate proc usp_testasselect * from testgo--执行存储过程exec usp_testgo
--有参存储过程创建和调用--创建存储过程user testif exists (select * from sysobjects where name=‘usp_test‘)drop proc usp_testgocreate proc usp_test@name varchar(32),@age int = nullas if @age is nullbegin select * from test where name = @nameendelse begin select * from test where name = @name and age = @ageendgo--调用存储过程exec usp_test @name=‘username‘go
--有参数、输出存储过程和调用--统计某年龄的人数--创建存储过程use testif exists (select * from sysobjects where name=‘usp_test‘)drop proc usp_testgocreate proc usp_test@age varchar(32),@count int outputas set @count = (select count(1) from test where age = @age)go--执行存储过程declare @age varchar(32)declare @count int set @age = ‘26‘exec usp_test @age ,@count outputprint @countgo
SQLServer存储过程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。