Defining tables and inserting data

SQL tables are created using the CREATE TABLE command as shown in the following SQL query:

CREATE TABLE musicians (id SERIAL PRIMARY KEY, name TEXT NOT NULL, born DATE, died DATE CHECK(died > born));

In this example, we're creating a table called musicians. After the name, we specify a list of column definitions. Each column definition follows the format column_name data_type constraints.

In this case, we have the following four columns:

  • The id column will be an arbitrary row ID. It's type is SERIAL, which means it will be an autoincrementing integer field, and its constraint is PRIMARY KEY, which means it will be used as the unique identifier for the row.
  • The name field is of type TEXT, so it can hold ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.