Jump to content

Sql 2005 Insert & Update Triggers


DaNuGai

Recommended Posts

I've used the code below for a MySQL database and it worked fine. However, now I am using an SQL 2005 database and I am trying to replicate the code below but I am having trouble converting the triggers. I understand that I can't use TIMESTAMP and instead I have to go with DATETIME data type but how do you write the same trigger for SQL 2005 database so it functions similar to the way it did in MySQL database.Thanks in advance.

CREATE TABLE EVENT (   EventID INT UNSIGNED NOT NULL AUTO_INCREMENT,   DateFrom DATE NOT NULL,   DateTo DATE NOT NULL,   EventTitle VARCHAR(50) NOT NULL,   Event TEXT NOT NULL,   Created TIMESTAMP DEFAULT '0000-00-00 00:00:00',   Updated TIMESTAMP DEFAULT '0000-00-00 00:00:00',   PRIMARY KEY(EventID));CREATE TRIGGER EVENT_TIME_CREATED   BEFORE INSERT ON EVENT   FOR EACH ROW SET NEW.Created = NOW(),    NEW.Updated = '0000-00-00 00:00:00';CREATE TRIGGER EVENT_TIME_UPDATED    BEFORE UPDATE ON EVENT   FOR EACH ROW SET NEW.Updated = NOW(),    NEW.Created = OLD.Created;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...