Home>Article>Database> How to use triggers in sql

How to use triggers in sql

青灯夜游
青灯夜游 Original
2019-05-13 14:46:30 4305browse

How to use triggers in sql

Usage of triggers

A trigger is a special stored procedure that occurs when the user attempts to Automatically executed when the table executes the specified data modification statement. You can use the CREATE statement to create a trigger, the DROP statement to delete the trigger, the ALTER statement to disable the trigger, etc. Let’s introduce it in detail below.

Create trigger

CREATE TRIGGER tr_update_Stock

Delete trigger

DROP TRIGGER tr_update_Stock

Disable

ALTER TABLE trig_example DISABLE TRIGGER trig1 GO

Recovery

ALTER TABLE trig_example ENABLE TRIGGER trig1 GO

Disable all triggers on a table

ALTER TABLE 你的表 DISABLE TRIGGER all

Enable all triggers on a table

ALTER TABLE 你的表 enable TRIGGER all

Disable all triggers on all tables

exec sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'

Enable all triggers on all tables

exec sp_msforeachtable 'ALTER TABLE ? enable TRIGGER all'

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

sql
Statement:
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