SQL Server Stored Procedures

Source: Internet
Author: User

1, stored procedure------Non-parametric stored procedure

---Creating a non-parametric stored procedure

Create proc Test1
As
Begin
SELECT * FROM Info
End

---Executing stored procedures

EXEC test1

---Removing stored procedures

drop proc Test1

2, the stored procedure------ with the entry parameter

---Creating a stored procedure with a parameter

Create proc Test3
(
@id INT--Enter parameter (default is input type argument)
)
As
Begin
SELECT * from info where [email protected]
End

-----Execution of stored procedures with parameters

--a:exec Test3 1

--b:exec test3 @id =1

3, stored procedure (Procedure)-bring in and out parameters

---to create a stored procedure with a parameter entry

Create proc Test2
(
@id int,--Enter parameter
@name varchar () out,--
@age int out--out parameter "Output ID"
)
As
Begin
Select @name =name, @age =age from info where [email protected]--out of the argument @ on the left of =
End

--Declaring variables

DECLARE @name1 varchar (), @age1 int;

--Call
EXEC test2 1, @name1 out, @age1 out

--Querying out the declared variables
Select ' Name ' [email protected], ' age ' [email protected]---Specify name1 column name, age1 column name is age

SQL Server Stored Procedures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.