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