summaryrefslogtreecommitdiff
path: root/doc/build/core/schema.rst
blob: 5a4f939bf7ef83563a269d53d6b02897c23dce67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.. _schema_toplevel:

==========================
Schema Definition Language
==========================

.. currentmodule:: sqlalchemy.schema

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
:class:`~sqlalchemy.schema.Table`, :class:`~sqlalchemy.schema.Column`,
:class:`~sqlalchemy.schema.ForeignKey` and
:class:`~sqlalchemy.schema.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 :class:`~sqlalchemy.schema.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.

.. toctree::
    :maxdepth: 3

    metadata
    reflection
    defaults
    constraints
    ddl