1 Reply Latest reply on Mar 5, 2008 1:24 AM by (Paul_Taylor)

    Delete master record if detail records are empty

      I have a simple question and response system
      the user enters their details (record stored in table called source - pkey as id_src)

      the user then goes on to answer questions (in a form)
      those responses are kept in a separate table (responses)
      with a foreign key in each response row telling me the ID of the source ie fk_id_src
      the form has a SUBMIT and CANCEL button

      PROBLEM
      If a user registers their details (created a source record with an ID)
      but fails to answer and questions (the response table does not have any foreign keys to that ID source)

      what is the best way to AUTOMATICALLY delete the user record (if there are no detail records in the response table)

      (note: the main response form IS NOT an ADDT form)

      the checking process needs to be triggered by the CANCEL button
      ie if the user presses submit - responses will be made to the questions - ie they will be empy answers - but in this case it is valid to do so

      I was wondering about a custom transaction - with delete SQL -
      or using check detail records - but cant see how to get that to fire the delete record transaction?

      any guidance appreciated

      tia

      Paul
        • 1. Re: Delete master record if detail records are empty
          Level 1
          OK

          I can create a separate page that checks if a detail record exists
          and display an error if it does

          on the same page I can add a delete transaction

          pass the master record id

          Both work, all OK so far

          BUT, the check detail throws its error message if detail records DOES EXIST

          I need to allow the delete transaction to run, if detail records DO NOT EXIST
          AND then
          redirect then page - wether the delete occurs or not

          any ideas?

          Paul