小标
2018-07-06
来源 :
阅读 1669
评论 0
摘要:本文主要向大家介绍了SQLServer数据库存储过程之新手导航,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
本文主要向大家介绍了SQLServer数据库存储过程之新手导航,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
我们今天主要向大家讲述的是SQL Server存储过程之入门学习,我们在创建SQL Server存储过程之前一般要先用use语句声明,要将存储过程存储在哪个相关的数据库中,以下就是文章的主要内容介绍。
1. e.g
2. use company;
执行之.之后就可以声明存储过程了.
1. e.g
2. create procedure ***
3. @id varchar(50) , @name int output
4. as
5. select @namename=name from table where id=@id
然后可以用alter对SQL Server存储过程进行修改.
declare可以声明一个变量
用set对变量赋值
1. e.g
2. alter proc getempp
3. @ID int
4. as
5. declare @Department int
6. select @Department=a.Department
7. from company.dbo.employee a
8. inner join company.dbo.department b
9. on a.Department=b.ID
10. where a.ID=@ID
11. if @@ROWCOUNT>0
12. begin
13. select *
14. from company.dbo.department
15. where ID=@Department
16. select * from company.dbo.employee
17. where Department=@Department
18. end
19. else
20. begin
21. RAISERROR('No record found',10,1)
22. end
上例中的@Department是被选择出来的值,然后用来为下面的if语句块中的查询服务的.
本文由职坐标整理并发布,了解更多内容,请关注职坐标SQL Server数据库频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号