Stored procedure: Just like a function
stored in the database--"programmability--" storage procedures
Create stored procedures: Save database tables, programmability, stored procedures
Create proc Jiafa
--Required parameters
@a int,
@b int
As
--Stored Procedure content
declare @c int;
Set @c [email protected] + @b;
return @c;
Go
Equivalent to a function
public int function name (variable 1, variable 2)
{
Function statements
return int C
}
Can be called directly after storage,
Executing stored procedures
EXEC Store Name
When there is a return value
declare @f int;
EXEC @f= Jiafa 3, 5;
Print @f;
--Example: Check the car table for the corresponding type of vehicle number
--Stored procedures
creat proc Chaxun
@n varchar (20)
As
DECLARE @num int
Select @num =coount (*) from car where name like '% ' [email protected]+ '% '
Go
--Call method
DECLARE @m int
exec @m=chaxun ' Audi '
Print @m
Trigger:
is a special stored procedure;
By adding or deleting the action to trigger the execution, no parameters, no return value;
The storage location is in the drop-down list of the table to be executed
Do not go to trigger not execute, meet the conditions after execution, equivalent to an event in HTML
Create TRIGGER Trigger Name
Insert_student-Name Specification Action _ The name of the table to be executed in order to understand the circumstances of the trigger to be used more easily
On Student-pin for that watch
For insert--triggers for that action
--onclick= "Show ()"
As
Code to be executed by the trigger
Go
1. For means to trigger after the action is executed
2, instead of Delete means that the deletion before the throw, can be understood as an alternative, write this after writing the code is useless, the code is covered by the trigger
When you delete the contents of a table that has a foreign key, you need to first delete the contents of the Foreign key connected table
Create Trigger Delete_info
On inf0
Instead of delete
As
DECLARE @c varchar (20)
Select @c =code from deleted
Delete from work where [email protected]
Delete from family where [email protected]
Delete from info where [email protected]
Go
Instead of use is more frequent than for
The interview process is more asked, but the actual work is relatively small
SQL Server databases (SQL sever language stored procedures and triggers)