title: MySQL trigger for checking values before insert multple times
body: <p>I have a table witch stores minimum and maximum air temperatures, sea water temperatures as "tinyint" and other params. Since I expect the new input to be between -50 and +50 degrees for air, I made a trigger on the table. But firstly I made this procedure:</p>
  
  <pre><code>    begin
      if temp&lt;-50 or temp&gt;50 then
      set sts = 0;
      else
      set sts = 1;
      end if;
      END
  </code></pre>
  
  <p>The trigger :</p>
  
  <pre><code>    BEGIN
      declare err boolean;
      declare msg varchar(255);
      call check_temp(NEW.Tmin,err);
      IF err!=1 THEN
      set msg = "Error: Tmin out of range.";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
      END IF;
  
      call check_temp(NEW.Tmax,err);
      IF err!=1 THEN
      set msg = "Error: Tmax out of range.";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
      END IF;
      END
  </code></pre>
  
  <p>As you can see, I call check_temp twice for the maximum and for the minimum values. 
  As I have more columns with meteorological parameters, I need to add their "range check" to the above trigger. </p>
  
  <p>My question is: is that the wisest thing to do? Using the procedure two times (and they are going to be three once I add the sea temperatures) like this, looks stupid to me. And checking all 8 parameters one by one in the trigger? I insert about 50 rows each time. Is it going to be much slower with the trigger? Up till now, I used PHP-side checking for this but decided to switch to the database capabilities instead. Can I use the trigger like that, or its purpose is completely different? Any advise on the topic will be appreciated. MySQL is 5.5.27</p>