Data Insertion Operations for Tables Associated with Foreign Keys

I'm currently working on a database data synchronization project. Because of the company's special requirements, it is necessary to write synchronized business code to achieve selective synchronization of database data. There are many data tables to be synchronized. Group tables by foreign key associations. Divided into 6 groups. Bring groups without foreign key associations to the front. The latter group correlates to the former group. And so on. Table data encapsulation objects are written to a file. Sync files to target station with rsync. The target station polls to read the data file into the library.

Because there is a foreign key association, when inserting data into the table. The database first checks to see if the value exists in the parent table associated with the associated field. If there is no parent table, or the value does not exist. Insertion fails. When data is stored in the database, the parent table is updated or saved first, and then the child table is updated or saved in the order of grouping.

However, on the target station, when the sql file is executed to create a table associated with a foreign key, it is not affected by the parent table.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326444059&siteId=291194637