Run SQL TRIGGER
Results 1 to 2 of 2

Thread: Run SQL TRIGGER

  1. #1
    Senior Member alirezaok's Avatar
    Join Date
    Oct 2003
    Location
    Qazvin City - Iran
    Posts
    320

    Run SQL TRIGGER

    hi

    I want to run this SQL:

    Code:
    CREATE TRIGGER customer_call AFTER INSERT ON cdr
    
    FOR EACH ROW Begin
        INSERT INTO smscalls (`id`,`from`,`to`,`state`,`sent`) VALUES (0,'1','1','1','0');
    
    END;
    but it gives me this error:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

    Note: only INSERT line works successfully Solely
    Last edited by alirezaok; 12-21-2013 at 03:26 AM.
    ***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    You need to change your delimiter when you define the trigger. Otherwise, MySQL thinks the ; at the end of your statement is the end of your trigger.
    Code:
    DELIMITER ~~
    
    CREATE TRIGGER customer_call AFTER INSERT ON cdr FOR EACH ROW
        BEGIN
            INSERT INTO smscalls (`id`,`from`,`to`,`state`,`sent`) VALUES (0,'1','1','1','0');
        END~~
    
    DELIMITER ;
    Also, is there a reason you're inserting the exact same record each time? (Unless there's an auto_increment primary key -that is NOT listed here- then only the first insert will succeed.) And why insert the id as a number, but the other cols as numeric strings?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •