SQL server:stored Procedures Stored Procedure primary article

Source: Internet
Author: User

For SQL Server, I'm a take doctrine. Many of the underlying principles do not understand, the direct imitation to take to use, to the error time, only to find the reasons and gradually into the bottom. I think, is every time the error, forcing me a little progress.

I need to write some stored procedures recently because of the project. At the same time, the school also opened a "database System" course. The combination of both satisfies my keen interest.

Write down my simple understanding of stored procedures.

First, the basic knowledge:

1.select,insert,update,delete's grammar, which is the core of the core

2. A little bit of programming basics: Understand basic control process languages such as If...else,wihle, for, assignment of variables, variable types, simple functions, etc.

Second, example: (Can observe the difference between the stored procedure and other programming languages, and then look at the following basic syntax, focusing on the difference between the two)

--Build a test tableCREATE TABLET2 ([Item_code] [varchar]( -)NULL,[Item_filename] [varchar]( -)NULL);
--stored procedures with input parameters and control flow statementsCREATE PROCEDURE [dbo].[Tansproc](@code_name varchar( -)) asBEGIN Insert intoT2 ([Item_code],[Item_filename])Values('1','Test 1'),('2','Test 2'),('3','Test 3'),('4','Test 4');if @code_name='1'begin Select 'Please re-enter' aswarning;EndElsebegin Select [Item_code],[Item_filename] fromT2whereItem_code like '%'+@code_name+'%'; EndEND--Executing stored proceduresexec [Tansproc] @code_name='1'

Results:

-- Executing stored procedures exec [tansproc] @code_name = ' 2 '

Results:

-- To Delete a stored procedure Drop PROCEDURE Tansproc

Three, basic grammar:

1.

Attention to detail:

C # Calling stored procedures

Resources:

1.https://msdn.microsoft.com/zh-cn/library/ms345415 (v=sql.120). aspx

SQL server:stored Procedures Stored Procedure primary 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.