Schema Definition Language

This section references SQLAlchemy schema metadata, a comprehensive system of describing and inspectingdatabase schemas.

The core of SQLAlchemy’s query and object mapping operations are supported bydatabase metadata, which is comprised of Python objects that describe tablesand other schema-level objects. These objects are at the core of three majortypes of operations - issuing CREATE and DROP statements (known as DDL),constructing SQL queries, and expressing information about structures thatalready exist within the database.

Database metadata can be expressed by explicitly naming the various componentsand their properties, using constructs such asTable, Column,ForeignKey andSequence, all of which are imported from thesqlalchemy.schema package. It can also be generated by SQLAlchemy using aprocess called reflection, which means you start with a single object suchas Table, assign it a name, and then instructSQLAlchemy to load all the additional information related to that name from aparticular engine source.

A key feature of SQLAlchemy’s database metadata constructs is that they aredesigned to be used in a declarative style which closely resembles that ofreal DDL. They are therefore most intuitive to those who have some backgroundin creating real schema generation scripts.