Mssql Stored Procedure introduction and instance application * First, let's take a look at the mssql Stored Procedure creation createprocedureproc_stuasselect * fromstudentgo creation process: Example of the following statement created in the architecture of the Human Resources Program remove_emp: Employee) mssql Stored Procedure entry and instance application
/*
First, let's take a look at mssql Stored Procedure Creation
Create procedure proc_stu
As
Select * from student
Go
Create a process: Example
The following statement creates the Human Resource program remove_emp in the architecture:
Create procedure remove_emp (employee_id NUMBER)
Tot_em NUMBER;
BEGIN
Delete from employees
WHERE employees. employee_id = remove_emp.employee_id;
Tot_emps: = tot_emps-1;
END;
For a simple example of the stored procedure, let's look at the syntax
CREATE {PROC | PROCEDURE} [schema_name.] procedure_name [; number]
[{@ Parameter [type_schema_name.] data_type}
[VARYING] [= default] [OUT | OUTPUT] [READONLY]
] [,... N]
[ [,... N]
[For replication]
AS { [;] [... N] | }
[;]
: =
[ENCRYPTION]
[RECOMPILE]
[Execute as Clause]
: =
{[BEGIN] statements [END]}
: =
External name assembly_name.class_name.method_name
Let's take a look at an instance in an instance application,
Query the Stored Procedure instance of a record with the id of 1
@ Total int OUTPUT
-----------------------------------
SET @ SQL = n' select a, B, c, d from t where id = 1'
Exec sp_executesql @ SQL, Int Out ', @ Total Out
-----------------------------------
Return @ Total
Instance 3
Add a record to the table book and query the total amount of all books in the table
Create proc insert_book
@ Param1 char (10), @ param2 varchar (20), @ param3 money, @ param4 money output
With encryption --------- encryption
As
Insert book (number, title, price) Values (@ param1, @ param2, @ param3)
Select @ param4 = sum (price) from book
Go
Example:
Declare @ total_price money
Exec insert_book '003 ', 'delphi control development Guide', $100, @ total_price
Print 'total amount is '+ convert (varchar, @ total_price)
Go
*/