DaNuGai Posted September 29, 2009 Share Posted September 29, 2009 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 More sharing options...
justsomeguy Posted September 29, 2009 Share Posted September 29, 2009 Check here:http://msdn.microsoft.com/en-us/library/ms...99(SQL.90).aspx Link to comment Share on other sites More sharing options...
DaNuGai Posted September 30, 2009 Author Share Posted September 30, 2009 Yeah I found that website when I googled SQL Triggers but I don't know what I was doing wrong but I wasn't able to replicate what I had listed above.Thanks for your help though. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.