Alibabacloud.com offers a wide variety of articles about create trigger sql server after update, easily find your create trigger sql server after update information here online.
Tags: io for ar art CTI on EF C SQLIn SQL Server, trigger, INSERT, UPDATE, delete state:CREATE TRIGGER t_inms_alarmsOn [PHS]. [dbo]. [Alarmcurrent]For INSERT, DELETEAsDECLARE @rows intSELECT @rows = @ @rowcountIF @rows = 0Return--If the table is inserted, synchronize the
Copy Code code as follows:
Create Trigger Tr_mastertable_update
On mastertable
After update
As
If update ([Type])--triggers this trigger when the Type field is updated
INSERT INTO masterlogtable
Select
Id
, (case [Type] when 1 Then ' Type1 '
When 2 Then ' Type2
Copy codeThe Code is as follows:Create trigger TR_MasterTable_UpdateOn MasterTableAfter updateAsIf update ([Type]) -- this trigger is triggered only when the Type field is updated.Insert into MasterLogTableSelectId, (Case [Type] when 1 then 'type1'When 2 then 'type2'When 3 then 'type3'When 4 then 'type4'Else 'typedefault'End), NameFrom insertedGo In addition, the
CopyCodeThe Code is as follows: Create trigger tr_mastertable_update
On mastertable
After update
As
If Update ([type]) -- this trigger is triggered only when the type field is updated.
Insert into masterlogtable
Select
ID
, (Case [type] When 1 then 'type1'
When 2 th
SQL Server DDL triggers (Trigger)-Create a database-level DDL triggerThe following invokes a trigger for a database when it is created, and writes the user account that created the data table to the event log in Windows.Create TRIGGER
SQL Server INSTEAD OF UPDATE view trigger problem, sqlserverinstead
An error occurs when the system's instead of update view trigger is associated with table UPDATE:
Message 414, level
Label:An error occurred when the INSTEAD of Update View Trigger association table update originated in the system is as follows: MSG 414, Level 16, State 1, line 1thUpdate is not allowed because the statement updates the view "Vtesttab" and the view participates in the join and has a INSTEAD of UPDATE
Classes;Update classes Set name = ' Five class ' WHERE name = ' Class 5 ';The update trigger saves the updated data in the deleted table after the data is updated, and the updated data is saved in the inserted table. # Update column-level triggers if (object_id (' Tgr_classes_update_column ', ' TR ') is not null)Drop
Example of a trigger codes:
Code of the insert, delete, and update trigger:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->-- DBO. trgroups. SQL
If exists (
Select * From sysobjects where
Name = 'trgroups' and type = 'tr ')
Begin
Drop
success.Create a trigger with the Create TRIGGER commandThe parameters are described as follows:Trigger_nameis the name of the trigger that the user is creating, must conform to the naming rules for MS SQL Server, and its name mu
Temporarily save inserted or updated record line Q You can check from the inserted table whether the inserted data meets business requirements Q if not, report an error message to the user and roll back the insert Operation Q deleted table Q temporarily saves the deletion or Record lines before update q you can check whether the deleted data meets the business requirements from the deleted table Q if it is not met, the error message is reported to th
Copy codeThe Code is as follows:-- Member tableIf object_id ('userinfo', 'U') is not nullDrop table userinfoGoCreate table userinfo (userid int primary key, user_tegral int, level int)Insert into userinfo select 1, 0, 0Go-- Member level tableIf object_id ('userlevel', 'U') is not nullDrop table userlevelGo-- Insert Test DataCreate table userlevel (level int primary key, mlevel_point decimal (10, 2 ))Insert into userlevel select 0, 0Insert into userlevel select 1,100Insert into userlevel select 2
SQL Server trigger and SQL Server triggerA trigger is a special type of stored procedure, which is different from the stored procedure we introduced earlier. A trigger is triggered by a
Copy Code code as follows:
--Member Table
If object_id (' UserInfo ', ' u ') is not null
drop table UserInfo
Go
CREATE TABLE userinfo (userid int primary key,user_tegral int,level int)
Insert INTO UserInfo Select 1,0,0
Go
--Membership Level table
If object_id (' userlevel ', ' u ') is not null
drop table Userlevel
Go
--Inserting test data
CREATE table userlevel (level int primary key,mle
SQL Server trigger and SQL Server triggerSQL Server triggers
A trigger is a special type of stored procedure, which is different from the stored procedure we introduced earlier. A
category
1 DML (Data Manipulation Language) trigger: indicates that the trigger is enabled when a DML event occurs in the database. DML events are the insert, update, and delete statements that modify data in tables or views.
2 DDL (Data Definition Language) trigger: It is used when a DDL event occurs on the
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.