sqlserver触发器转换为Postgresql语句中的触发器

oracle_1010 发布于 2012/06/24 11:52
阅读 436
收藏 0

sqlserver中触发器语句如下,可否帮忙把如下的例子给小弟转换为postgresql中的触发器语句,初学postgresql,所以不是太了解,故请大家帮忙,先谢谢了

IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'tri_DeviceStatus_insupd' AND type = 'TR')
   DROP TRIGGER tri_DeviceStatus_insupd
GO
CREATE TRIGGER tri_DeviceStatus_insupd
ON DeviceStatus
FOR INSERT, UPDATE
AS
DECLARE @devID varchar(50),
   @devStatus varchar(30),
   @devMsg    varchar(30),
   @uID  int
BEGIN
  select @uID=UserID,@devID=DID,@devStatus=Status from  inserted i
  if @devID = 'security_Kitchen_SmokeAlarm'
  begin
  if(@devStatus = 'State=On')
    select @devMsg='发生报警'
  else
    select @devMsg='停止报警'
   insert into Message values(4,@uID ,'烟雾报警器',@devMsg,getDate())
  end
 else if @devID = 'security_Balcony_Magnetic'
  begin
   if(@devStatus = 'State=On')
    select @devMsg='发生报警'
  else
    select @devMsg='停止报警'
   insert into Message values(4,@uID ,'门磁感应',@devMsg,getDate())
  end
 else if @devID = 'security_Lobby_Move'
 begin
   if(@devStatus = 'State=On')
    select @devMsg='发生报警'
  else
    select @devMsg='停止报警'
   insert into Message values(4,@uID ,'移动感应',@devMsg,getDate())
  end
END
加载中
返回顶部
顶部