home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / database / oracle / 2255 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  2.8 KB

  1. Xref: sparky comp.databases.oracle:2255 comp.databases.sybase:364
  2. Newsgroups: comp.databases.oracle,comp.databases.sybase
  3. Path: sparky!uunet!gator!rde!andy
  4. From: andy@homebase.vistachrome.com (Andy Finkenstadt)
  5. Subject: Re: Table Design Hint needed
  6. Message-ID: <1992Nov19.172834.16594@homebase.vistachrome.com>
  7. Reply-To: andy@homebase.vistachrome.com
  8. Organization: Vista-Chrome Incorporated
  9. References: <BxxqJ4.Cs0@ccu.umanitoba.ca>
  10. Date: Thu, 19 Nov 1992 17:28:34 GMT
  11. Lines: 69
  12.  
  13.  
  14. Without duplication of data, the many-to-many relationship is best
  15. expressed as an intersection table:
  16.  
  17. create table DIRECTORS (
  18.   pk_director number not null primary key,
  19.   dir_name char(40) not null
  20. ) ;
  21. create table BUSINESSES (
  22.   pk_business number not null primary key,
  23.   bus_name char(40) not null
  24. ) ;
  25. create table BUS_DIR_XREF (
  26.   fk_business number not null references BUSINESSES,
  27.   fk_director number not null references DIRECTORS,
  28. ) ;
  29. create unique index pk_bus_dir_xref (fk_business,fk_director);
  30. create unique index pk_bus_dir_xref (fk_director,fk_business);
  31.  
  32. It may serve your purposes to define a view pre-joining these tables:
  33.  
  34. create view BUSINESS_DIRECTORS as
  35.   select pk_business business, pk_director director, 
  36.     bus_name, dir_name
  37.   from BUSINESSES, DIRECTORS, BUS_DIR_XREF
  38.   where fk_business=pk_business
  39.     and fk_director=pk_director
  40.   ;
  41.  
  42.  
  43. Now you can do selects like this:
  44.  
  45.   select business, bus_name
  46.   from BUSINESS_DIRECTORS
  47.   where bus_name='INTERNATIONAL BUSINESS MACHINES'
  48.   ;
  49.  
  50. Enjoy.
  51. -Andy
  52.  
  53. PS - this was typed with verification against SQL.  There might be
  54. some C-isms that creeped in .
  55.  
  56.  
  57. ummalik@ccu.umanitoba.ca (Ijaz Rashid Malik) writes:
  58. >Hello,
  59. >I have to design two tables and I need some help to minimize the duplication
  60. >etc.
  61. >One table is "businesses" and key fields is business ID.
  62. >Other is "directors" and key is dir. ID.
  63. >A business can have more than one directors and a director can control more
  64. >than one business.
  65. >Both table have to be linked so that all directors for a given business or
  66. >all businesses under given director could be listed.
  67. >My thinking either calls for mulitple Dir. ID. columns in business table
  68. >(dir1. ID, dir2. ID...) but its not practicle as # of directors varies. OR
  69. >same director could be listed in directors table under different ID's and 
  70. >there is a column (field) called Business ID which points to the business
  71. >controlled by this person but problem with this is that same record is listed
  72. >multiple times ==> redundancy!!!
  73. >Could someone please help me out here with some hints...
  74. >Thanks very much!
  75. >Malik
  76. >ummalik@ccu.umanitoba.ca
  77. -- 
  78. Andrew Finkenstadt, Vista-Chrome, Inc., Homes & Land Publishing Corporation
  79. GEnie Unix RoundTable Manager, andy@vistachrome.com, andy@genie.geis.com.
  80.   Join GEnie, call 800-638-9636/301-251-6415.  Join Unix, CASE, and Desktop 
  81.   Oracle RDBMS Database discussions, send mail to ora-request@vistachrome.com
  82.