Trigger exampleCodeWhen the monitoring data exceeds the set warning value based on real-time data, insert the data into the abnormal data table.
Use [mointor] Go/****** object: trigger [DBO]. [realtimedata_trg] script Date: 08/15/2013 13:20:55 *****/set ansi_nulls ongoset quoted_identifier ongo alter trigger [DBO]. [realtimedata_trg] on [DBO]. [t_pn_realtimedata] After insert as/** Data Exception The newly inserted value is greater than the maximum value configured in the device table t_pn_device **/If (select max_value from t_pn_device where device_code = (select device_id from inserted)) <= (select monitor_value from inserted) Begin declare @ num int -- Monitoring value select @ num = monitor_value from inserted; declare @ device_id varchar (20) -- Monitoring Device number select @ device_id = device_id from inserted; insert into values (ID, alarm_value, device_code, exception_code, exception_style, exception_time, normal_value, pipe_code, status) values (newid (), @ num, @ device_id, '000000', 'out of the normal range', convert (varchar (100), getdate (), 20 ),'','', '0'); print 'exception info have been inserted into t_oa_data_exception '; End
Dml@2013.8.15