Create or replace trigger update_sys_ins_tasks
Before update on sys_inst_tasks
For each row
Declare
-- Local variables here
Finished number;
Nowproc varchar2 (4000 );
Begin
Finished: =: New. finished;
Nowproc: =: New. nowproc;
If finished = 1 and nowproc <> 'complete' then
: New. nowproc: = 'awaiting printing ';
: New. task_status: = 1;
: New. createtime: = sysdate;
End if;
End update_sys_ins_tasks;
1. The same table is used to change some fields in the table when data is updated in the table ..
Trigger name update_sys_ins_tasks
Name of the table to be changed when data is updated: sys_inst_tasks
Finished number; nowproc varchar2 (4000); these two are trigger conditions.
: New. nowproc: = 'awaiting printing ';: New. task_status: = 1;: New. createtime: = sysdate; these are the content I want to update.
2. When the sb_yzrwjlb table contains data, update the basic device data table.
Update_jcsjb: the trigger name.
Table where sb_yzrwjlb triggers data.
RW indicates the fields in the data update or insertion in the sb_yzrwjlb trigger data table.
The device basic data table updates the fields in this table when RW updates data.
What is different from the above is that the operation is performed on two tables. The operation is performed on one table.
Create or replace trigger update_jcsjb
After insert or update on sb_yzrwjlb
For each row
Begin
If: New. RW like 'service % 'then
Update Device basic data table set device basic data table. Usage = 'stopped' where device basic data table. asset code =: New. zcbm;
Elsif: New. RW like 'break % 'then
Update Device basic data table set device basic data table. Usage = 'idle 'Where device basic data table. asset code =: New. zcbm;
Else
Update Device basic data table set device basic data table. Usage = 'in use-busy 'Where device basic data table. asset code =: New. zcbm;
End if;
End;
After changing SQL server to a certain field according to the field specified in the same table, the other field is also changed. Trigger
Set ansi_nulls onset quoted_identifier ongoalter trigger [DBO]. [tri_gzdb_rwhb] on [DBO]. [gzdb_rwhb] for update as begindeclare @ zgld varchar (50), @ guid varchar (50) If Update (zgld) beginselect @ zgld = zgld, @ guid = guid from inserted if @ zgld = 'zhangguo' update gzdb_rwhb set zyld = 'zhangguo' where guid = @ guid -- Update gzdb_rwhb set zyld = 'aaa' endend
Gzdb_rwhb is the table name of the update field,
Declare @ zgld varchar (50), field name to be updated
@ Zgld is the defined variable.
@ Guid varchar (50) is
The primary key of the gzdb_rwhb table.
Select @ zgld = zgld, @ guid = guid from inserted to the variable defined earlier
@ Zgld,
@ Guid
Assign values.
If @ zgld = 'zhangguo', if the condition is 'zhangguo', The zyld field will be updated to 'zhangguo '.
Update gzdb_rwhb set zyld = 'zhangguo' where guid = @ guid according
Primary Key guid of the gzdb_rwhb table
Update the zyld column as 'zhangguo '.