存储过程的示例 [英] examples of stored procedures
本文介绍了存储过程的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请你分享一些存储过程的例子
解决方案
你好,
请参阅以下文章
SQL Server存储过程概述 [ ^ ]
Sql Server - 如何在Sql server中编写存储过程 [ ^ ]
< a href =http://www.mssqltips.com/sqlservertutorial/168/different-options-for-creating-sql-server-stored-procedures/> http://www.mssqltips.com/sqlservertutorial/168/不同的选项-F or-creating-sql-server-stored-procedures / [ ^ ]
一切顺利:)快乐学习
看到:
Sql Server - 如何在Sql server中编写存储过程 [ ^ ]
及更多这里
< a href =https://www.google.co.in/#q=examples+of+stored+procedures&safe=off> https://www.google.co.in/#q=examples+of +存储+程序& safe =关闭 [ ^ ]
请阅读代码项目快速解答常见问题解答 [ ^ ]在发布另一个问题之前
存储过程是一组T-SQL(Transact SQL)语句。如果您遇到一种情况,一遍又一遍地写同一个查询,您可以将该特定查询保存为存储过程并仅通过它的名称来调用它。
使用输入参数创建存储过程:此SP接受GENDER和DEPARTMENTID参数。参数和变量名称中带有@前缀。
创建程序spGetEmployeesByGenderAndDepartment
@Gender nvarchar(50),
@DepartmentId int
as
开始
从tblEmployee中选择名称,性别性别= @Gender和DepartmentId = @DepartmentId
结束
然后使用以下语法执行您的程序:
1.执行spGetEmployeesByGenderAndDepartment'男性',1(这里的分配值的顺序应相同因为我在创建输入参数时使用它)
2.EXECUTE spGetEmployeesByGenderAndDepartment @ DepartmentId = 1,@ Gender ='Male'
Can you please share some more examples of stored procedures
解决方案
Hello,
pls refer the following articles
Overview of SQL Server Stored Procedure[^]
Sql Server - How to write a Stored procedure in Sql server[^]
http://www.mssqltips.com/sqlservertutorial/168/different-options-for-creating-sql-server-stored-procedures/[^]
All the best:) Happy learning
See this :
Sql Server - How to write a Stored procedure in Sql server[^]
and more here
https://www.google.co.in/#q=examples+of+stored+procedures&safe=off[^]
and please read Code Project Quick Answers FAQ[^] before posting another question
A stored procedure is group of T-SQL (Transact SQL) statements. If you have a situation, where you write the same query over and over again, you can save that specific query as a stored procedure and call it just by it's name.
Creating a stored procedure with input parameters: This SP, accepts GENDER and DEPARTMENTID parameters. Parameters and variables have an @ prefix in their name.
Create Procedure spGetEmployeesByGenderAndDepartment
@Gender nvarchar(50),
@DepartmentId int
as
Begin
Select Name, Gender from tblEmployee Where Gender = @Gender and DepartmentId = @DepartmentId
End
then execute your procedure using on of the below syntax:
1. EXECUTE spGetEmployeesByGenderAndDepartment 'Male', 1 ( here the order of assiging value should be same as i it is used while creating the input parameter)
2.EXECUTE spGetEmployeesByGenderAndDepartment @DepartmentId=1, @Gender ='Male'
这篇关于存储过程的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文