| re: Referential Integrity - How to update a table?
"Mike Dole" <m_doolio@hotmail.com> wrote in message
news:fddbbab7.0408040806.51460133@posting.google.c om...
| Thanks for your help guys!
|
| I didn't want to go through the database table by table, record by
| record, check the existence, update the record it it existed, inserted
| if not, delete if neccesary, etc, etc.
|
| But at the end I:
| - put the (empty) tables who gave me integrity problems in the 'source
| database'.
|
| made a script that:
| - filled them 'TEMPORARY' with the records from the original database
| - deleted these records in the original database
| - deleted the records of the remaining tables and inserted the new
| ones from my source database.
| - Inserted the records from the Temporary tables back into the
| original.
| - Deleted the records in the temporary tables (in case our customer
| would run the script twice..).
|
| It works, you can run it multiple times, but the code's not a pretty
| sight to look at..
|
For this or future tasks, you might look into a series of update,
append, and delete queries. If the records are identified with primary
keys, for each table you can run:
1. An update query, joining existing records in both tables, updating
all data values from source to the target.
2. An append query, left joining one table to the other, setting a where
condition of PrimaryKey Is Null in the target, which will append any new
records.
3. A delete query, right joining one to the other, where PrimaryKey Is
Null in the source, which will delete records in the target that no
longer exist in source.
Typically you would do the deletions in a table order so that dependent
data is deleted first (i.e. delete the orders, then the customers), and
do the appends in the reverse order (add the new customers, then add
their new orders).
(from comp.lang.basic.visual.database) |