MySQL Forums
Forum List  »  Triggers

Re: Trigger error
Posted by: Peter Brawley
Date: May 06, 2016 03:48PM

SQL is radically different from the dBase family of databases, which are non-relational. You need to get up to speed on relational DBs, eg with ...

http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch01.html

http://www.artfulsoftware.com/dbdesignbasics.html

Re your error, creating stored routines consisting of multiple logical lines requires DELIMITER directives to tell MySQL when to turn stored routine analysis on and off, eg ...

delimiter //
create trigger ...;
//
delimiter ;

You could get round that difficulty with this Trigger by rewriting it as one logical line ...

create trigger `fc1_before_update` before update on `fc1` for each row 
  set new.total = ifnull(new.h1_qty,0) + ifnull(new.h2_qty,0) + ifnull(new.h3_qty,0) + 
                  ifnull(new.h4_qty,0) + ifnull(new.h5_qty,0) + ifnull(new.h6_qty,0) + 
                  ifnull(new.h7_qty,0) + ifnull(new.h8_qty,0) + ifnull(new.h9_qty,0) + 
                  ifnull(new.h10_qty,0) + ifnull(new.h11_qty,0) + ifnull(new.h12_qty,0) + 
                  ifnull(new.h13_qty,0) + ifnull(new.h14_qty,0) + ifnull(new.h15_qty,0) + 
                  ifnull(new.h16_qty,0) + ifnull(new.h17_qty,0),
      new.total_lbs = new.total/453.592;

But there are other problems:

1. Your total and total_lbs values are logically redundant, ie they're just sums of other values in the row. It is probably more efficient to sum them in a View, or if you are using MySQL 5.7, in derived columns (read about those in the 5.7 manual).

2. Table columns named xxx1, xxx2, ... usually indicate normalisation failure. (Read about normalisation.) Your need to sum them confirms that. To address that problem, let's see the present table structure as described by ...

Show Create Table fc1;

Options: ReplyQuote


Subject
Views
Written By
Posted
1343
May 06, 2016 02:51PM
Re: Trigger error
659
May 06, 2016 03:48PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.