Quick import or load of multiple DB2 Master/Slave tables case description

Source: Internet
Author: User

This article mainly describes how to import or load multiple DB2 Master/Slave tables correctly and quickly. If you perform the actual operation steps on import or load multiple DB2 Master/Slave tables, if you are interested, you can browse the following articles.

Problem

During routine database maintenance, database administrators sometimes need to move a large amount of data between different databases, and the data has the relationship between the master and slave tables in our business, when exporting, importing, or loading data, we may encounter errors such as SQL0530N and SQL0668N. How can we avoid these errors, to ensure that these operations can be completed correctly and quickly?

Answer

Suppose we have created the following two DB2 Master/Slave tables:

 
 
  1. CREATE TABLE PARENTT(ID INT NOT NULL,  
  2. NAME CHAR(20) NOT NULL,  
  3. CONSTRAINT P_PT PRIMARY KEY(ID))  
  4. CREATE TABLE CHILDT (ID INT NOT NULL,  
  5. CNAME CHAR(40) NOT NULL,  
  6. PID INT,  
  7. CONSTRAINT P_CT PRIMARY KEY(ID),  
  8. CONSTRAINT F_CT FOREIGN KEY (PID) REFERENCES PARENTT (ID) ON DELETE CASCADE)  

If no data is imported into the primary table PARENTT, we will encounter the SQL0530N error when using IMPORT to IMPORT data from the table CHILDT, the reason is that the foreign key constraints of IMPORT need to check the integrity of the reference. If there is no relevant record in the master table, the data cannot be imported.

 
 
  1. db2 "import from child.del of del insert into childt"  
  2. SQL0530N FOREIGN KEY "HUANGDK.CHILDT.F_CT" 

The insert or update value of is not equal to any parent key value of the parent table.

If you use the LOAD method, you can LOAD data because the LOAD is designed to ignore the constraints check during loading, but when querying data, you will encounter SQL0668N RC = 1

 
 
  1. db2 "load from child.del of del insert into childt"  
  2. db2 "select * from childt"  

SQL0668N is not allowed to perform operations on the table "HUANGDK. CHILDT", cause code "1 ".

The cause code "1" indicates that the table "HUANGDK. CHILDT" is in the "check pending" status. The reference integrity of the slave table "HUANGDK. CHILDT" is not checked forcibly, and the table content may be invalid. If the slave table is in the check pending status, the operation on the parent table or basic table that is not in the check pending status may also receive this error.

After loading the data of the primary table PARENTT, you can use the following statement to restore the table to a normal state:

 
 
  1. db2 set integrity for huangdk.childt immediate checked 

For operations that require loading a large number of DB2 Master/Slave tables, the preceding statements will waste a lot of time on the database administrator. If the preceding statements are executed before the master table data is loaded, an error of SQL0530N is also reported.

In fact, if we load or import the data in the master table first, we will not encounter the above error, nor need to execute the set integrity statement to greatly simplify the operation. We can find the table's master-slave relationship from the System View SYSCAT. REFERENCES by using the following SQL statement:

Db2 "select substr (REFTABSCHEMA,) as master table mode, substr (REFTABNAME,) as master table, substr (TABSCHEMA,) as slave table mode, substr (TABNAME, 1, 30) as from table from SYSCAT. REFERENCES"

Master table mode
Master table
Slave table mode
Slave table

 

 
 
  1. ASN_DOWN_TC_M6101 IBMQREP_SENDQUEUES ASN_DOWN_TC_M6101 IBMQREP_SUBS  
  2. ASN_DOWN_TC_M6101 IBMQREP_SUBS ASN_DOWN_TC_M6101 IBMQREP_SRC_COLS  
  3. HDK PARENTT HDK CHILDT 


The above content is an introduction to how to import or load multiple DB2 Master/Slave tables correctly and quickly. I hope you will gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.