Abstract:
The invention meeting the need identified above is the “Enhanced Database Propagation Program” or (EDPP). EDPP uses a cyclic member table that identifies a first source table in a cyclic relationship with a second source table. The first source table, identified in the cyclic member table, propagates first. EDPP replaces all foreign keys with “NULL” in the first target table. After the second source table in the subscription set has propagated to a second target table, EDPP updates first target table with the foreign keys from the first source table.

Description:
[0001]    This application is a continuation of U.S. patent application Ser. No. 11/427,930 filed Jun. 30, 2006, status allowed. 
     
    
     FIELD OF THE INVENTION 
       [0002]    The present invention relates generally to database maintenance in a computer or digital processing system, and relates particularly to a method of propagating tables while preserving cyclic foreign key relationships. 
       BACKGROUND OF THE INVENTION 
       [0003]    A database is any collection of information organized for rapid search and retrieval. A database stored in a computer-readable medium is commonly modeled as a collection of one or more tables. Each table, in turn, is modeled as a collection of one or more records (also commonly referred to as a “row”), and each record as a collection of one or more fields (also commonly referred to as a “column”). In a conventional table, all records comprise the same number and type of fields, and in the same order. A relational database consists of tables that are “related” to each other through common fields. The most common way to establish a relationship between two tables is to include one or more fields in each table that hold “key” information. A “primary key” field uniquely identifies a record, and commonly is just a number unrelated to other data in the record. A “foreign key” field is an identifier in a record that establishes a relationship with a primary key in another table. For example, employee records might have an “employee” table containing a “department_id” field that references data located in a “department” table&#39;s “dept_id” field. In this example, the dept_id field uniquely identifies each department, while the department_id field identifies the department in which an employee works. Thus, in this example, dept_id would be a primary key, and department_id would be the foreign key that establishes the relationship between the employee table and the department table. The integrity of the table relationship depends on the foreign key referencing a valid primary key. Most modern database management systems allow users to designate foreign key fields when tables are created, and subsequently reject operations that would result in an invalid foreign key reference. Thus, all foreign key values must have equivalent primary key values that already exist in the other table. 
         [0004]    As is well known in the art, it is sometimes advantageous to replicate databases on other computers or servers, or even on the same computer or server. It is common, though, for a database to hold thousands of tables and millions of records, and replicating these databases can be a difficult and cumbersome task. Several software tools exist in the art to assist a database administrator with the task of replicating (also called “propagating”) databases among servers, including DpropR—a database utility developed by IBM. On the most basic level, DpropR extracts data from a first “source” database on a first server and pushes the data to a second “target” database on a second server. DpropR removes “foreign keys” from the second or target database. When supporting two-way propagation, where data is propagated in both directions between the two databases, DpropR also removes “foreign keys” from the first or source database. An improvement to DropR (see discussion of U.S. patent application Ser. No. 10/855,736 below) allows a database administrator to control the order of propagation to preserve foreign key integrity, and thereby eliminates the need to remove foreign keys. 
         [0005]    In order to propagate databases between servers, DpropR or other database propagation utilities use “subscription sets” to determine which tables should be propagated, and to which servers. A subscription set generally comprises a list of tables that a database administrator or user treats as a single unit for purposes of database propagation. A database administrator specifies in advance what tables are included in a subscription set, and can create more than one subscription set if needed or desired. 
         [0006]    Subscription sets are themselves typically stored in relational tables: a “subscription” table and a “member” table. A subscription table comprises records identifying a subscription set, the server having the source database to be copied, and the target database to which the source database should be copied. The subscription set may also contain other useful information, such as a value indicating the last time the source database was copied, and a value indicating a frequency for copying the source table. 
         [0007]    A member table comprises records identifying a source table, the subscription set to which the source table belongs, and the name of the target table to which the source table should be copied. Each subscription set identified in the member table must have a corresponding record in the subscription table. Note, though, that a source table can appear in more than one subscription set. 
         [0008]    U.S. patent application Ser. No. 10/855,736 (the &#39;736 application) discloses a method and apparatus for propagating relational database tables that allow a database administrator to control the order of propagation, and thereby preserve foreign key integrity. The &#39;736 application&#39;s improvement to DpropR or other database propagation utilities adds an additional field to each member table and subscription set called ORDER. The additional field enables an administrator or other user to assign a rank to each subscription set and to each table within a subscription set, and then use the rankings to determine the order in which to propagate database tables. The rankings ensure that tables with a primary key referenced by a foreign key are propagated before the table with the foreign key is propagated, avoiding an invalid foreign key reference. 
         [0009]    One embodiment of the improvement disclosed in application Ser. No. 10/855,736 uses two programs CAPTURE and APPLY. CAPTURE monitors a database for changes and causes APPLY to propagate source tables of the subscription sets in the designated order. Something that U.S. patent application Ser. No. 10/855,736 explicitly does not address is the situation of “cyclic foreign keys.” Cyclic foreign keys occur when a field in TABLE 1  references a field in TABLE 2 , which in turn references a field in TABLE 1 . Illustrated below as: 
         [0000]      TABLE1→TABLE2→TABLE1
 
         [0000]    Of course, cyclic references can be more complex, involving more than two tables: 
         [0000]      TABLE1→TABLE2→TABLE3→TABLE1
 
         [0010]    An example of TABLE 1  and TABLE 2  with a cyclic relation are shown in  FIG. 1  and  FIG. 2 . TABLE 1  in  FIG. 1  has three columns: T 1 _COL 1 , T 1 _COL 2  and T 1 _COL 3 . The first column, T 1 _COL 1 , contains primary keys. The second column, T 1 _COL 2  contains additional data, and the third column, T 1 _COL 3  contains foreign keys referencing a primary key in the first column (T 2 _COL 1 ) of TABLE 2 . Likewise, TABLE 2  in  FIG. 2  has three columns: T 2 _COL 1 , T 2 _COL 2  and T 2 _COL 3 . The first column, T 2 _COL 1 , contains primary keys. The second column, T 2 _COL 2  contains additional data, and the third column, T 2 _COL 3  contains foreign keys referencing a primary key in the first column (T 1 _COL 1 ) of TABLE 1 . Propagating either TABLE 1  or TABLE 2  to another server without propagating the other table results in an invalid foreign key reference in the third column. 
         [0011]    Simply propagating tables in a specific order does not work with cyclic references. One of the tables has to propagate first, which inevitably results in an invalid foreign key reference unless the foreign references are manually removed from the target table to be propagated. A need exists for a system and method to automatically propagate tables containing cyclic references, without permanently removing any foreign keys. 
         [0012]    These and other objects of the invention will be apparent to those skilled in the art from the following detailed description of a preferred embodiment of the invention. 
       SUMMARY OF THE INVENTION 
       [0013]    The invention meeting the need identified above is the “Enhanced Database Propagation Program” or (EDPP). EDPP uses a “cyclic member table” that identifies a first source table with cyclic foreign key relationships with a second source table. The first source table, identified in the cyclic member table, propagates first. EDPP replaces all foreign keys with “NULL” in the first target table. After the second source table in the subscription set has propagated to a second target table, EDPP updates the first target table with the foreign keys from the first source table. 
         [0014]    The EDPP also works when there are more than two interrelated tables. All tables, save the last one, must be copied to target tables with “NULL” replacing the foreign keys. Then, EDPP copies the last table to a last target table, which includes the foreign keys. After the last table is copied, the preceding tables are updated with the original foreign keys. The procedure for more than two tables is usually done in a particular sequence, where the tables are copied in a particular order, and then updated and the reverse order. 
     
    
     
       BRIEF DESCRIPTION OF DRAWINGS 
         [0015]    The novel features believed characteristic of the invention are set forth in the appended claims The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will be understood best by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein: 
           [0016]      FIG. 1  is an exemplary table with foreign keys; 
           [0017]      FIG. 2  is an exemplary table with foreign keys; 
           [0018]      FIG. 3  is an exemplary network; 
           [0019]      FIG. 4  describes programs and files in a memory on a computer; 
           [0020]      FIG. 5  is a flowchart of an Apply program; 
           [0021]      FIG. 6  is a flowchart of an Update program; and 
           [0022]      FIG. 7A-7E  is an example propagation of tables with a cyclic relationship. 
       
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT 
       [0023]    The principles of the present invention are applicable to a variety of computer hardware and software configurations. The term “computer hardware” or “hardware,” as used herein, refers to any machine or apparatus that is capable of accepting, performing logic operations on, storing, or displaying data, and includes without limitation processors and memory; the term “computer software” or “software,” refers to any set of instructions operable to cause computer hardware to perform an operation. A “computer,” as that term is used herein, includes without limitation any useful combination of hardware and software, and a “computer program” or “program” includes without limitation any software operable to cause computer hardware to accept, perform logic operations on, store, or display data. A computer program may, and often is, comprised of a plurality of smaller programming units, including without limitation subroutines, modules, functions, methods, and procedures. Thus, the functions of the present invention may be distributed among a plurality of computers and computer programs The invention is described best, though, as a single computer program that configures and enables one or more general-purpose computers to implement the novel aspects of the invention. For illustrative purposes, the inventive computer program will be referred to as the “Enhanced Database Propagation Program” or (EDPP). 
         [0024]    Additionally, the EDPP is described below with reference to an exemplary network of hardware devices, as depicted in  FIG. 3 . A “network” comprises any number of hardware devices coupled to and in communication with each other through a communications medium, such as the Internet. A “communications medium” includes without limitation any physical, optical, electromagnetic, or other medium through which hardware or software can transmit data. For descriptive purposes, exemplary network  100  has only a limited number of nodes, including workstation computer  105 , workstation computer  110 , server computer  115 , and persistent storage  120 . Network connection  125  comprises all hardware, software, and communications media necessary to enable communication between network nodes  105 - 120 . Unless otherwise indicated in context below, all network nodes use publicly available protocols or messaging services to communicate with each other through network connection  125 . 
         [0025]    EDPP  400  typically is stored in a memory, represented schematically as memory  420  in  FIG. 4 . The term “memory,” as used herein, includes without limitation any volatile or persistent medium, such as an electrical circuit, magnetic disk, or optical disk, in which a computer can store data or software for any duration. A single memory may encompass and be distributed across a plurality of media. Further, EDPP  400  may reside in more than one memory distributed across different computers, servers, logical partitions or other hardware devices. The elements depicted in memory  420  may be located in or distributed across separate memories in any combination, and EDPP  400  may be adapted to identify, locate and access any of the elements and coordinate actions, if any, by the distributed elements. Thus,  FIG. 4  is included merely as a descriptive expedient and does not necessarily reflect any particular physical embodiment of memory  420 . As depicted in  FIG. 4 , though, memory  420  may include additional data and programs. Of particular importance to EDPP  400 , memory  420  may include Resource Data  430  which includes Source_Tables  440 . Source_Tables  440  are database tables that are to be propagated. As with the prior art identified above, EDPP  400  uses subscription sets and member tables. By way of example, subscription sets are represented here as Subscription_Table  450 . A special member table lists database tables with cyclic foreign keys, shown here as Cyclic_Member_Table  460 . As with the prior art, Subscription_Table  450  and Cyclic_Member_Table  460  include an “ORDER” field, indicating an order of propagation. Cyclic_Member_Table  460 , however, does not include the last database table with cyclic foreign keys to be propagated. For example, if two tables have cyclic foreign keys, then only the first table to be propagated is included in Cyclic_Member_Table  460 . If three tables have cyclic foreign keys, then only the first two tables to be propagated are included, and so forth. EDPP  400  has three component programs: Apply  500 , Update  600  and Capture  700 . 
         [0026]      FIG. 5  shows a flowchart of Apply  500 . As with the prior art identified above, Apply  500  starts ( 510 ) as a response to a detected change by Capture  700 , or otherwise initiated by a database administrator manually or automatically by another program or process. Capture  700  is known in the art, and causes Apply  500  to propagate database tables in response to detected changes in the source database tables. Apply  500  scans the records from Subscription_Table  450  for Cyclic_Member_Table  460  ( 512 ). Apply  500  determines if there are any tables with cyclic foreign key references ( 514 ). If no tables are listed with cyclic foreign key references, tables propagate normally under the prior art ( 524 ). If tables with cyclic foreign references are listed, Apply  500  iterates through the records listed in Cyclic_Member_Table  460  ( 516 ). In addition to records indicating tables with cyclic foreign keys, Cyclic_Member_Table  460  may specify a particular order for propagating the list of tables. Apply  500  creates a target database table for the next table to propagate ( 518 ). Apply  500  then copies the source database table to the target database table, replacing every foreign key reference with a “NULL” statement ( 520 ). Only a NULL statement can be used because any other word will cause a check for the foreign key, and such a check for a foreign key will cause a violation error to be thrown. Apply  500  determines if there are more tables listed in Cyclic_Member_Table  460  ( 522 ), and if so, repeats steps  516 - 520 . Once all tables listed in Cyclic_Member_Table  460  are copied, the other tables in Subscription_Table  450  propagate normally under the prior art ( 524 ). Once all tables in Subscription_Table  450  propagate, Apply  500  determines if cyclic foreign references were propagated ( 526 ). If tables with cyclic foreign references were propagated, Apply  500  initiates Update  600  ( 528 ), otherwise, Apply  500  stops ( 530 ). 
         [0027]      FIG. 6  shows a flowchart of Update  600  start when initiated by Apply  500  ( 610 ). Update  600  iterates through the records of tables listed in Cyclic_Member_Table  460  in reverse order ( 612 ). Update  600  copies all the foreign key references from the source table to the target table ( 614 ). Since all tables referenced by the foreign key are populated, there will not be a foreign key violation error. Update  600  determines if there are more tables listed in Cyclic_Member_Table  460  ( 616 ), and if so, repeats steps  612 - 614 . Once all tables listed in Cyclic_Member_Table  460  are copied, Update  600  stops ( 618 ). 
         [0028]      FIG. 7A-7E  shows the propagation of the source tables with cyclic foreign key references shown in  FIG. 1  and  FIG. 2  using EDPP  400 . Target_Table_ 1  is created in  FIG. 7A .  FIG. 7B  shows Target_Table_ 1  populated with data from TABLE_ 1 , but the foreign key references in column T_T 1 _COL 3  have been replaced with “NULL.” Target_Table_ 2  is created in  FIG. 7C .  FIG. 7D  shows Target_Table_ 2  populated with data from TABLE_ 2 , including the foreign key references in column T_T 2 _COL 3 . There will not be a foreign key violation error after the propagation of Target_Table_ 2 , because Target_Table_ 1  has been created and populated with data, although some records are merely placeholders.  FIG. 7E  shows Target_Table_ 1  updated with the original foreign key references, completing the propagation process. 
         [0029]    A preferred form of the invention has been shown in the drawings and described above, but variations in the preferred form will be apparent to those skilled in the art. The preceding description is for illustration purposes only, and the invention should not be construed as limited to the specific form shown and described. The scope of the invention should be limited only by the language of the following claims.