Page 1 of 1

Creating Trigger in MySQL

Posted: Tue 28 Apr 2009 06:48
by Moehre
Hello!

I have a problem in creating a trigger in mysql using UniQuery Component:

CREATE TRIGGER trtest BEFORE UPDATE OF test FOR EACH ROW
BEGIN
SET NEW.Datum = CURRENT_TIMESTAMP;
END;

After reading some examples of creating triggers in MySQL I realized, that always a special delimiter was declared:

DELIMITER //
CREATE TRIGGER ...
END;//

In SQL Workbench I must use this DELIMITER clause to create the trigger or an error occurs. How can I create a trigger using UniQuery in MySQL?

Thx
Moehre

Posted: Tue 28 Apr 2009 07:34
by Dimon
To create a trigger using TUniQuery you should only set the SQL property to appropriate SQL statement and call the Execute method, like this:

Code: Select all

  UniQuery1.SQL.Clear;
  UniQuery1.SQL.Add('CREATE TRIGGER trtest BEFORE UPDATE ON test FOR EACH ROW ');
  UniQuery1.SQL.Add('BEGIN ');
  UniQuery1.SQL.Add('SET NEW.Datum = CURRENT_TIMESTAMP; ');
  UniQuery1.SQL.Add('END;');
  UniQuery1.Execute;

Posted: Tue 28 Apr 2009 09:45
by Moehre
That did it! Thank you!