views:

117

answers:

1

i want to check if a table row exist with a trigger. if it does then it does nothing, but if it doesnt exist it inserts a row.

here is my current code i want to modify.

BEGIN
IF (NEW.counter >= 100) THEN
// check if a certain row exists in another table, if not, execute the beneath code
INSERT INTO tagCategories (name, counter) VALUES ('unnamed', NEW.counter);
UPDATE tagCategories2tagPairs SET tagCategoryId = LAST_INSERT_ID() WHERE tagPairId = OLD.id;
END IF;
END

is there any good tutorials on this, teaching all functions you can use with a trigger (they dont look like the php functions)

+1  A: 

mysql trigger tutorial

CREATE TRIGGER Syntax

For the restrictions on behaviour allowed in Triggers, please see:

D.1. Restrictions on Stored Routines, Triggers, and Events

To check if row exists and update it, otherwise insert a row if it does not exist, you can use the INSERT INTO ... ON DUPLICATE KEY UPDATE statement, but within the restrictions for triggers mentioned in the above link.

Mitch Wheat
a lot to read...is what i want to do possible?
weng
reading is good: it improves ones skills...
Mitch Wheat