How do I extract the SQL statements required to move all tables and views from an existing database to another database?

Lennart Jorelid

Boy, this is a big one. :) The operation is performed in 9 steps:

  1. Open a connection to the source database. Use the DriverManager class.
  2. Find the entire physical layout of the current database. Use the DatabaseMetaData interface.
  3. Create DDL SQL statements for re-creating the current database structure. Use the DatabaseMetaData interface.
  4. Build a dependency tree, to determine the order in which tables must be setup. Use the DatabaseMetaData interface.
  5. Open a connection to the target database. Use the DriverManager class.
  6. Execute all DDL SQL statements from (3) in the order given by (4) in the target database to setup the table and view structure. Use the PreparedStatement interface.
  7. If (6) threw exceptions, abort the entire process.
  8. Loop over all tables in the physical structure to generate DML SQL statements for re-creating the data inside the table. Use the ResultSetMetaData interface.
  9. Execute all DML SQL statements from (8) in the target database.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact