Starting from Mysql 5.0.2, mysql now supports triggers - which can be quite handy. I'm using them to automatically create new (derived) table records when a user submits data to my web app. Syntax is very clean (as follows) http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html:
CREATE TABLE test1(a1 INT);
CREATE TABLE test2(a2 INT);
CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE test4(
a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
b4 INT DEFAULT 0
);
DELIMITER |
CREATE TRIGGER testref BEFORE INSERT ON test1
FOR EACH ROW BEGIN
INSERT INTO test2 SET a2 = NEW.a1;
DELETE FROM test3 WHERE a3 = NEW.a1;
UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
END;
|
DELIMITER ;
http://www.advogato.org/article/858.html
On an unrelated note, I just read the other day that Oracle has acquired the company that wrote the InnoDB Mysql engine (which is the real one that enforces foreign keys and transactions etc).
http://developers.slashdot.org/article.pl?sid=07/04/01/1448207&from;=rss On another unrelated note, you can now use Postgresql as a MySQL database engine - how cool is that?