Release: 1.2.8 | Release Date: May 28, 2018

# SQLAlchemy 1.2 Documentation

# Schema Definition Language

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

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

Database metadata can be expressed by explicitly naming the various components and their properties, using constructs such as `Table`, `Column`, `ForeignKey` and `Sequence`, all of which are imported from the `sqlalchemy.schema` package. It can also be generated by SQLAlchemy using a process called reflection, which means you start with a single object such as `Table`, assign it a name, and then instruct SQLAlchemy to load all the additional information related to that name from a particular engine source.

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

- Describing Databases with MetaData
  - Accessing Tables and Columns
  - Creating and Dropping Database Tables
  - Altering Schemas through Migrations
  - Specifying the Schema Name
  - Backend-Specific Options
  - Column, Table, MetaData API
- Reflecting Database Objects
  - Overriding Reflected Columns
  - Reflecting Views
  - Reflecting All Tables at Once
  - Fine Grained Reflection with Inspector
  - Limitations of Reflection
- Column Insert/Update Defaults
  - Scalar Defaults
  - Python-Executed Functions
  - SQL Expressions
  - Server Side Defaults
  - Triggered Columns
  - Defining Sequences
  - Default Objects API
- Defining Constraints and Indexes
  - Defining Foreign Keys
  - UNIQUE Constraint
  - CHECK Constraint
  - PRIMARY KEY Constraint
  - Setting up Constraints when using the Declarative ORM Extension
  - Configuring Constraint Naming Conventions
  - Constraints API
  - Indexes
  - Index API
- Customizing DDL
  - Custom DDL
  - Controlling DDL Sequences
  - Using the built-in DDLElement Classes
  - DDL Expression Constructs API