home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / database / oracle / 1564 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  2.9 KB

  1. Path: sparky!uunet!mcsun!sunic!psinntp!psinntp!dlogics!hermes.dlogics.com!dlm
  2. From: dlm@hermes.dlogics.com
  3. Newsgroups: comp.databases.oracle
  4. Subject: On reversing the master-detail relationship.
  5. Message-ID: <1992Sep10.122259.1310@hermes.dlogics.com>
  6. Date: 10 Sep 92 12:22:59 CST
  7. References: <1992Sep3.163521.26698@cbfsb.cb.att.com> <1992Sep7.115156.1307@hermes.dlogics.com> <1992Sep8.122538.14511@cbfsb.cb.att.com>
  8. Organization: Datalogics, Inc., Chicago, IL
  9. Lines: 59
  10.  
  11. colten@cbnewsb.cb.att.com (marc.colten) writes:
  12. > dlm@hermes.dlogics.com writes:
  13. >> colten@cbnewsb.cb.att.com (marc.colten) writes:
  14. >> > 3)  Can you do a query on a detail block and have the relevant
  15. >> >     information come up in the master block? [...]
  16. >> > 
  17. >> [...] just write triggers that treat
  18. >> KEY-ENTQRY and KEY-EXEQRY in the detail exactly as if they are in the master,
  19. >> but with the block associations reversed. 
  20. >
  21. > If I do a "go_block(master)" and then a query, it wipes out the
  22. > values of the master block and waits for input.  I can't find a
  23. > function that takes the current values and runs with them.
  24.  
  25.     REVERSING THE MASTER-DETAIL RELATIONSHIP.
  26.  
  27. The detail's foreign key is enforced from the master block primary key. The
  28. master is generally coded with no key enforcement. So, enforce its primary key
  29. from the detail block's foreign key. As long as the detail is cleared prior to
  30. querying the master, the master-detail will work; if the master is cleared
  31. prior to querying the detail, the detail-master will work. You will have to
  32. write the triggers yourself (cannibalize the master-detail procedures).
  33.  
  34. The scenario will run something like this:
  35.  
  36.     master    key-entqry    go_block(detail);
  37.                 clear_block;
  38.                 go_block(master);
  39.                 enter_query;
  40.                 go_block(detail);
  41.                 execute_query;  [not enter_query]
  42.                 go_block(master);
  43.  
  44.     detail    key-entqry    go_block(master);
  45.                 clear_block;
  46.                 go_block(detail);
  47.                 enter_query;
  48.                 go_block(master);
  49.                 execute_query;  [ditto]
  50.                 go_block(detail);
  51.  
  52. The same principle is employed for the case of key-exeqry. This is the 
  53. simplest method i can think of. 
  54.  
  55. Remember most of all that the detail-master relation makes an end-run around
  56. the relational concept of key inheritance.
  57.  
  58. If you do not query on a foreign key, the rows returned will belong to many
  59. masters. the behavior of the form is predictable: only one master will be
  60. returned since its primary key can be enforced from only one detail row. This
  61. presents a very misleading view of the relationship. If you solve this problem
  62. by querying only on the detail's foreign key, you will have accomplished
  63. little, since this action is the same as querying on the master's primary key.
  64.  
  65. In short, although you can jury-rig the detail-master relationship, it is
  66. mostly pointless to do so. Net flames to /dev/nul or NLA0: please.
  67. --
  68. Dave Mausner, Senior Consultant / Datalogics Inc / Chicago IL / 312-266-4450
  69. dlm@dlogics.com                                 Motto: Just show me the code
  70.