title: creating a trigger in oracle that uses data from another table
body: <p>I am trying to create a trigger in a table called race that enforces a constraint which is "STARTDATE&lt;=MEETING.ENDDATE"</p>
  
  <p>in other words <em>startdate</em> from the race table must be less than or equals to  to the <em>enddate</em> of the meetings table (THE STARTDATE CANNOT BE RUN AFTER THIS DATE!)</p>
  
  <p>I would like the trigger to fire when adding a record to the race table and the startdate entered is wrong (startdate is after the enddate of the meetings table)</p>
  
  <p>I have created this so far but I don't know if I'm right or how I finish it!</p>
  
  
  
  <pre><code>CREATE OR REPLACE TRIGGER race_date_trg    
  BEFORE INSERT OR UPDATE
    ON RACE
    FOR EACH ROW
    WHEN (NEW.RACEID)
     DECLARE STARTDATE DATE;
    BEGIN
      SELECT * FROM meeting INTO VARIABLE
      IF STARTDATE &lt;= ENDDATE THEN
        INSERT INTO RACE (STARTDATE) VALUES (:n.startdate);
      else
    end (race_date_trg);
  </code></pre>
  
  <p>Thank-you for your help!</p>