home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / TEXT / PDX_ALL.ZIP / TI127.ASC < prev    next >
Text File  |  1991-11-04  |  6KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  127
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  November 4, 1991                         PAGE  :  1/3
  12.  
  13.     TITLE  :  Normalizing a non-normalized Paradox table
  14.  
  15.  
  16.  
  17.  
  18.   This information sheet demonstrates the best method for
  19.   converting a non-normalized table into a table in the first
  20.   normal form.  In brief, a non-normalized table is one in which
  21.   repeating groups of information are spread out over many fields
  22.   rather than placing them into a few fields with many records.
  23.   For example, let's say you have a table which tracks orders
  24.   placed by a number of customers over a single year.  We want this
  25.   table to display the Customer Number and the number of products
  26.   purchased for each month.  For simplicity's sake we will assume
  27.   the year only has three months (January, February, and March).
  28.   Here is the non-normalized version of this table:
  29.  
  30.   Orders═╦═Customer #╦═January ╦═February═╦═March═╗
  31.          ║   0001    ║   3     ║      7   ║   0   ║
  32.          ║   0002    ║   0     ║      1   ║   0   ║
  33.          ║   0003    ║   0     ║      0   ║  14   ║
  34.  
  35.  
  36.   This is the normalized version:
  37.  
  38.   Orders═╦═Customer #╦══Month═══╦═Quantity═╗
  39.          ║   0001    ║ January  ║      3   ║
  40.          ║   0001    ║ February ║      7   ║
  41.          ║   0001    ║ March    ║      0   ║
  42.          ║   0002    ║ January  ║      0   ║
  43.          ║   0002    ║ February ║      1   ║
  44.          ║   0002    ║ March    ║      0   ║
  45.          ║   0003    ║ January  ║      0   ║
  46.          ║   0003    ║ February ║      0   ║
  47.          ║   0003    ║ March    ║     14   ║
  48.  
  49.   The first table is keyed on Customer # only.  All information
  50.   related to a single customer is stored in a single record with
  51.   many fields.  The second table is keyed on both Customer # and
  52.   Month.  Each customer has three records (twelve if we were
  53.   dealing with a full year), one for each month, and that month's
  54.   corresponding quantity.  It is necessary to do number of queries
  55.   to convert the data from the format of the first table to the
  56.   format of the second table.  More specifically two queries must
  57.   be performed for each group to be incorporated into the
  58.   consolidated fields (i.e. for each month of the year in this
  59.   example).
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox                                NUMBER  :  127
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  November 4, 1991                         PAGE  :  2/3
  78.  
  79.     TITLE  :  Normalizing a non-normalized Paradox table
  80.  
  81.  
  82.  
  83.  
  84.   To begin the process you must create a new table with the proper
  85.   structure (one which looks like the second table).  Once this is
  86.   done the following two queries must be performed for each field
  87.   to be converted:
  88.  
  89.   QUERY #1 (this is a multi-table query):
  90.  
  91.   OrdersA╦═Customer #╦═January═╦═February═╦═March═╗
  92.          ║ _Cust     ║ _Quant  ║          ║       ║
  93.  
  94.  
  95.   OrdersB╦═Customer #╦══Month═══╦═Quantity═╗
  96.   Insert ║ _Cust     ║          ║ _Quant   ║
  97.  
  98.   This insert query links the OrdersA Customer # field to to the
  99.   OrdersB Customer # field and the OrdersA January quantity field
  100.   to the OrdersB Quantity field.  The key word "Insert" tells
  101.   Paradox to copy the data from the OrdersA fields which contain
  102.   example elements Cust and Quant to their corresponding fields in
  103.   OrdersB.  The underscore (_) stands for the example element key
  104.   (F5).
  105.  
  106.   Once Query #1 is performed the OrdersB table will look like this:
  107.  
  108.   OrdersB╦═Customer #╦══Month═══╦═Quantity═╗
  109.          ║   0001    ║          ║      3   ║
  110.          ║   0002    ║          ║      0   ║
  111.          ║   0003    ║          ║      0   ║
  112.  
  113.   All of the records whose month values are blank should now be
  114.   assigned the Month value of January.  Query #2 performs this
  115.   operation (Note: clear the workspace before proceeding using
  116.   (Alt-F8):
  117.  
  118.   QUERY #2:
  119.  
  120.   OrdersB╦═Customer #╦═══════════Month══════════╦═Quantity═╗
  121.          ║           ║  BLANK, CHANGETO January ║          ║
  122.  
  123.   Once this is performed, clear Query #2 from the workspace (F8)
  124.   and set up Query #1 again.  Move the example element Quant in
  125.   OrdersA to the next field to be incorporated into the OrdersB
  126.   table (in this case the February field) and run the query.  The
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  127
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  November 4, 1991                         PAGE  :  3/3
  144.  
  145.     TITLE  :  Normalizing a non-normalized Paradox table
  146.  
  147.  
  148.  
  149.  
  150.   February values and corresponding Customer #'s are now inserted
  151.   into the OrdersB table.  Once again all the newly inserted
  152.   records have a blank Month value.  Clear the workspace and set up
  153.   Query #2, this time changing blank values to the new Month value
  154.   (February).  To complete the process simply step through this set
  155.   of queries until all fields have been incorporated into the new
  156.   OrdersB table.
  157.  
  158.   NOTES:
  159.  
  160.   1. This is a generic example, however, the concept is applicable
  161.   to any database in which repeating fields contain the same type
  162.   of data.  Keep in mind, the only things that change from query
  163.   set to query set is the location of the example element in Query
  164.   #1 and the label for the new records in Query #2.
  165.  
  166.   2. Use {Scripts} {QuerySave} to store the two queries the first
  167.   time around.  This will save you the time and effort involved in
  168.   re-creating the queries for each step of the process.
  169.  
  170.   3. See the general Normalization TI "Explanation of Normalized
  171.   and Non-Normalized Tables" for further discussion of the theory
  172.   behind normalization.
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.