Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    104

    how to deal with conditional participation (n00bness)

    Greetings again, and thanks for viewing yet one more noob inquiry.

    (I've attached a jpeg file with erd.)

    I have three tables -- operators, haulsystems, and harvestsystems. My business rules dictate that: a. any given operator does not need to be entered into the haulsystems table AND the harvest systems table. But, b. the operator must be entered in either the haulsystem table OR the harvestsystem table. If an operator is not associated with either a haulsystem or a harvestsystem, then that operator will not appear in the operators table.

    The relationship between operators and haulsystems is one-to-many and the participation of operators with haulsystems is optional, while the participation of haulsystems with operators is mandatory. (An operator does not have to be involved with haulsystems -- conditionally -- but a haulsystem does have to be involved with an operator -- and only one operator.) The same relationship exists between operator and harvestsystem.

    So, how do I logically handle this condition, given that participation is "sort-of" or conditionally optional... and (thereby) conditionally mandatory? Again, thanks.
    Attached Thumbnails Attached Thumbnails ERD example.jpg  
    Last edited by rbfree; 02-14-09 at 16:14.

  2. #2
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    In SQL if you enforce such conditions then in most cases the tables cannot be updated. Standard SQL does not permit simultaneous updates involving multiple tables and therefore it is not feasible to enforce a constraint that a value must always exist in Table A and some other table(s). Because of this limitation referential constraints in SQL are usually designed to be optional at one end or the other - even where the business rules imply otherwise.

    As a workaround there is something called a "deferrable" constraint, which is a constraint that can be turned off for the duration of a transaction. This is not ideal in every case but if your DBMS supports it then it is a workaround.

  3. #3
    Join Date
    Feb 2009
    Posts
    104

    thanks

    For now, I'll keep participation optional on between operators and children. Then, later I'll rethink constraints and delve into the sql topics you've brought up. Once I'm solid on a revisable design, I'll directly plunge into sql.

    Many thanks.

Posting Permissions

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