日期:2014-05-16  浏览次数:20918 次

sqlserver触发器转换为postgresql
sqlserver中触发器语句如下,想转换为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



------解决方案--------------------
错误信息是什么? 先把其中语句全部删除,然后一句一句加。