liveBook · Manning

Column

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A named field in a relational database table whose cells contain values of a defined or compatible type.

A column is a named field in a database table. Each row is a record, while each column holds one kind of field value, such as text, an integer, a decimal number, or a binary object. Unlike a delimited CSV field, a database column has a defined data type. section 10.3.1

Columns become more useful when their definitions describe how records fit into the larger application:

  • A primary-key column uniquely identifies each record; in the Customer table, customer_id is an integer primary key. section 10.3.1 section 10.6.1
  • A foreign-key column references another table's primary key, creating a relationship between records. section 10.3.1 section 10.6.1
  • A model definition gives each column a name and compatible type while allowing SQLAlchemy to map Python attributes to database fields. section 10.6.1

A column in a SQLAlchemy model

A Customer model can define customer_id = db.Column(db.Integer, primary_key=True) and name = db.Column(db.String). The first column identifies each customer and can be auto-incremented; the second stores the customer's name. An Order model can define customer_id as a foreign key pointing to customer.customer_id. section 10.6.1

Figure 10.6 The ERD diagram for the Customer table showing the field names and data types

Use the ERD to scan a table's column names, data types, and primary-key designation before translating the design into model classes. section 10.3.1

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains columns through table structure, ERD notation, key constraints, and SQLAlchemy declarations, but not database engine internals.
Examples
Uses Customer, Order, Address, Product, and Item models with typed columns, primary keys, foreign keys, and a composite key.
What it assumes
Assumes familiarity with records and CSV files while introducing relational tables, ERD notation, keys, and ORM mappings.
What you can do after
Build database models by assigning names, types, primary keys, and foreign-key references to columns.
How it connects
Connects columns with tables, rows, data types, primary keys, foreign keys, entity relationship diagrams, and SQLAlchemy models.

Also explained in

Compare how 9 books explain column →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.