SQL Server Stored Procedures and triggers

Source: Internet
Author: User

I used to understand concepts. I have no in-depth understanding. I found some materials for study last night. Take notes on your understanding. When you are doing something, you can directly splice SQL statements with databases, and rarely use stored procedures and parameters.

Stored Procedure: a set of T-SQL statements stored in the database, which can be called multiple times in the program by compiling once. In addition, parameters and output parameters can be transmitted to the statement to prevent injection attacks. The stored procedure is more efficient and reduces network traffic.

Definition Syntax of stored procedure:

Create procedure procedure_name [; number]

(

@ Parame1 data_type [output],

......

)

AS

SQL statement

 

 

Procedure_name: name of the stored procedure

[; Number]: an optional integer used to group processes with the same name, so that the same group can be removed with a drop procedure statement. For exampleProc; 1,Proc; 2. When you want to delete this set of stored procedures, you can use DROP PROCEDUREOrderprocThe statement removes the entire group.

@ Parame: defines the parameter name.

Data_type: Define the parameter type

Output: an optional parameter. When the output limit is added after the parameter, this parameter is specified as the returned parameter.

 

 

Trigger: A trigger is created only for insert, update, and delete operations on a table. The trigger is automatically executed.

Trigger Syntax:

Create trigger name

On indicates

For [insert | update | delete]

As

SQL statement

 

The difference between a trigger and a stored procedure: a trigger does not need to be called in a program. It is automatically triggered when the corresponding operation is performed on the table. The stored procedure is compiled and called directly in the program if necessary.

 

Related 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.