home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / database / oracle / 2551 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  2.6 KB

  1. Path: sparky!uunet!hayes!fgreene
  2. From: fgreene@hayes.com
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: SQL*Loader foreign key problem
  5. Message-ID: <6558.2b3048c0@hayes.com>
  6. Date: 17 Dec 92 09:30:40 EDT
  7. References: <1go4ktINNarb@fmsrl5.srl.ford.com>
  8. Organization: Hayes Microcomputer Products, Norcross, GA
  9. Lines: 54
  10.  
  11. In article <1go4ktINNarb@fmsrl5.srl.ford.com>, hugh@slee01.srl.ford.com (Hugh Fader) writes:
  12. > I am having a problem with SQL*Loader and foreign keys. I have two
  13. > tables:
  14. > CREATE TABLE components(
  15. >  id                              NUMBER(4,0)      NOT NULL,
  16. >  confignum                       NUMBER(3,0)      NOT NULL
  17. >  [other stuff deleted]
  18. > )
  19. > CREATE TABLE conventional_data(
  20. >  id                              NUMBER(4,0)      NOT NULL,
  21. >  comp_id                         NUMBER(4,0)      NOT NULL,
  22. >  [other stuff deleted]
  23. > )
  24. > The conventional_data.comp_id column is a foreign key which references
  25. > components.id.
  26. > Here is my problem: I am trying to load data into the
  27. > conventional_data table using SQL*Loader. Each row in the external
  28. > file contains a confignum value which is assumed to pre-exist in the
  29. > components table. How can I assign a value to
  30. > conventional_data.comp_id that points to the appropriate row in the
  31. > components table? It seems as though I would have to use a SQL select
  32. > in order to do this. Have I hit the limit as to what SQL*Loader can
  33. > do?
  34. > --
  35. > Hugh Fader
  36. > Ford Research Laboratory
  37. > hugh@slee01.srl.ford.com
  38. Using SQL*Loader, insert the data directy into the conventional_data 
  39. table with a NULL value assigned to comp_id.  After the load is complete,
  40. run a SQL*Plus script to update the conventional_data table and synch
  41. the values to the components table.  Something like:
  42.  
  43.     update conventional_data A
  44.     set    comp_id = (select id 
  45.                           from   components B
  46.                   where  B.confignum = B.confignum)
  47.     Where  comp_id is null;
  48.  
  49.   ---------------------------------------------------------------------------
  50.   |      Frank Greene                  |          //////  //////             |
  51.   |      DELPHI SYSTEMS, Inc.          |           ////    ////              |
  52.   |      Telephone [615] 458-6032      |          ////    ////  //////       |
  53.   |      324 Ootsima Way               |         ////    ////    ////        |
  54.   |      Loudon, TN 37774              |        //////  //////  //////       |
  55.   ----------------------------------------------------------------------------
  56.   |         Of course, any opinions or suggestions are strictly my own       |
  57.   ----------------------------------------------------------------------------
  58.  
  59.