Module: jet2sql—Creating a SQL DDL from an Access Database
Credit: Matt Keranen
If you need to migrate a
Jet (Microsoft Access
.mdb) database to
another DBMS system, or need to understand the Jet database structure
in detail, you must reverse engineer from the database a standard
ANSI SQL DDL description of its schema.
Example 8-1 reads the structure of a Jet database file using Microsoft’s DAO services via Python COM and creates the SQL DDL necessary to recreate the same structure (schema). Microsoft DAO has long been stable (which in the programming world is almost a synonym for dead) and will never be upgraded, but that’s not really a problem for us here, given the specific context of this recipe’s use case. Additionally, the Jet database itself is almost stable, after all. You could, of course, recode this recipe to use the more actively maintained ADO services instead of DAO (or even the ADOX extensions), but my existing DAO-based solution seems to do all I require, so I was never motivated to do so, despite the fact that ADO and DAO are really close in programming terms.
This code was originally written to aid in migrating Jet databases to larger RDBMS systems through E/R design tools when the supplied import routines of said tools missed objects such as indexes and FKs. A first experiment in Python, it became a common tool.
Note that for most uses of COM from Python, for best results, you need to ensure that Python has read and cached the type library. Otherwise, for example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access