SQL Stored Procedures: Creating and Using

SQL stored procedures are an executable program module that can be stored in a database as various objects. In other words, this is an object that contains SQL statements. These stored procedures can be executed in the application client to get good performance. In addition, such objects are often called from other scripts or even from some other section.

MS SQL Server Stored Procedures




Introduction

, (, MS SQL). , . , . , . , DDL DML, ( – UDF).

SQL , . , , – , , . 2005-2010 , "" «SQL Server Management Studio». , . . MS SQL Server , , «» , «».





. : , , . DDL-, . , . .

. , , PL/SQL Oracle, PSQL InterBase Firebird, «» Transact-SQL. , . , , , , , , .

. , , . , , . . , SQL: , , .









, . , . , .

Microsoft SQL Server stored procedures




SQL . , ( ) SQL. , (, , ) , , SQL, , :

- Output;

- ;

- .

, .

1. EXEC- SQL

MS SQL (Managment Studio). , , . SQL EXEC-, .

, , . . (), , , .

Creating a SQL Stored Procedure




, , , . , Microsoft SQL Server. .

, , , , . , .

SQL, , , , . . :

- - ;

- ;

- .

2.

, . . .

, , . , @. , . , @NAME1 ​​ . . , , .

: « ?» . , , . : , «Select Var = ». , .

3. SQL

. , , ( ). , . , , , . , , Pubs, . , , Google SQL SQL2005.

SQL stored procedure call




, @State @City. , . @TotalAuthors ( ), . , . , .

SQL

. , , . , ( ). @State @City. . . , . .

. , , . @City , @State . . SQL . , , «UT» «». @City, @State «». , . , , .

SQL execute stored procedure




4. SQL Server:

. :

- ;

- ;

- .

4.1 SQL

. . , , . , , .

, , . , . , Select-, , Select @RetValue, OutputValue.

4.2 SQL

, . Output . - «Output» . , . SQL, , .

SQL stored procedure with parameters




: @TotalAuthors @TotalNoContract. . . , , .

, , , MS SQL Server . «CA». , , . , . , , , , .

4.3 SQL

(RecordSet) . SQL @AuthID «» @AuthId. Select , . AuthId . . - . , .

SQL stored procedures examples




, , . , ( ) . SQL, , , . T SQL, , . , , , , , .




All Articles