How to create sql database trigger

王林
Release: 2020-07-07 11:02:36
Original
7753 people have browsed it

The method to create a sql database trigger is: [create trigger trigger_name on table_name as sql_statement]. A trigger is a special stored procedure that triggers execution when inserting, updating, or deleting operations are performed on the table.

How to create sql database trigger

#What is a trigger?

(Recommended learning:mysql tutorial)

A trigger is a special stored procedure that triggers execution when inserting, updating, or deleting a table.

Triggers are generally used to check constraints or process some subsequent transaction logic. The difference between triggers and ordinary stored procedures is that triggers operate on a certain table.

For example: when operations such as update, insert, and delete are performed, the system will automatically call and execute the corresponding trigger on the table. So triggers can be used to implement complex integrity constraints on tables.

Add creation syntax

create trigger trigger_name   on {table_name | view_name}   {for | After | Instead of }   [ insert, update,delete ]   as   sql_statement
Copy after login

Modify syntax

alter trigger trigger_name--类似于修改表结构
Copy after login

Delete syntax

drop trigger trigger_name
Copy after login

View triggers

select * from sys.triggers select * from sysobjects where xtype='TR'
Copy after login

View single trigger

exec sp_helptext '触发器名'
Copy after login

The above is the detailed content of How to create sql database trigger. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!