MySQL Forums
Forum List  »  Newbie

Help converting Trigger SQL Server code to MYSQL
Posted by: justin liao
Date: April 11, 2005 03:11PM

Hi, I was wondering if anyone could help me. I have been trying to write a trigger for MYSQL from MS SQL Server code but I've been having some problems. Does anyone know if MYSQL has those virtual tables "deleted" and "inserted" that SQL Server uses?

Any help would be appreciated. Thanks.

This is the SQL Server code that I'm trying to change to MYSQL:

USE [pubs]

SET QUOTED_IDENTIFIER OFF
GO

IF EXISTS (SELECT name FROM sysobjects
WHERE name = "mDBpkstub" AND type = "U")
DROP TABLE [mDBpkstub]
GO

CREATE TABLE [mDBpkstub] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[TransTime] [datetime] NOT NULL ,
[PK] [varchar] (50) NOT NULL ,
[LayerName] [varchar] (50) NOT NULL ,
[Type] [int] NOT NULL ,
[Status] [int] NOT NULL )

ALTER TABLE [mDBpkstub] ADD
CONSTRAINT [PK_mDBpkstub] PRIMARY KEY CLUSTERED
(
[id]
)
GO

IF EXISTS (SELECT name FROM sysobjects
WHERE name = "mDBpush_Authors" AND type = "TR")
DROP TRIGGER [mDBpush_Authors]
GO

CREATE TRIGGER [mDBpush_Authors] ON [Authors] FOR INSERT, UPDATE,
DELETE AS

IF NOT EXISTS (SELECT * FROM INSERTED) -- "inserted" table is empty so must be delete trigger
INSERT INTO mDBpkstub (TransTime,PK,LayerName,Type,Status)
SELECT GetDate(),au_id,"Authors",3,0 FROM deleted
ELSE IF NOT EXISTS (SELECT * FROM DELETED) -- "deleted" table is empty so must be insert trigger
INSERT INTO mDBpkstub (TransTime,PK,LayerName,Type,Status)
SELECT GetDate(),au_id,"Authors",2,0 FROM inserted
ELSE -- both tables have entries so must be update trigger
INSERT INTO mDBpkstub (TransTime,PK,LayerName,Type,Status)
SELECT GetDate(),au_id,"Authors",1,0 FROM inserted
GO

Options: ReplyQuote


Subject
Written By
Posted
Help converting Trigger SQL Server code to MYSQL
April 11, 2005 03:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.