--- title: Tables description: Create and drop tables in simple mode and in advanced-mode SQL, including compound primary keys. sidebar: order: 2 --- A table is the core building block. This page covers creating and removing tables; changing a table's columns after it exists is covered in [Columns](/reference/columns/). ## Create a table (simple mode) The simplest way to create a table is `with pk` on its own — it gives the table a ready-made primary-key column named `id` that the database fills in for you: ```rdbms create table authors with pk ``` Prefer to name the key, or give it a specific type? Name it in the `with pk` clause: ```rdbms create table authors with pk author_id(serial) ``` Either way, the rest of the columns are added afterwards with `add column`: ```rdbms add column to authors: name (text) add column to authors: birth_year (int) ``` ### Compound primary keys To make the primary key span more than one column, list them, comma separated: ```rdbms create table loans with pk book_id(int), member_id(int) ``` **Syntax** ```rdbms-syntax create table with pk [()[, ...]] ``` ## Create a table (advanced mode) In advanced mode you write a full `CREATE TABLE` with every column and constraint inline: ```sql create table authors ( author_id serial primary key, name text not null, birth_year int ) ``` The advanced form also accepts table-level constraints and inline foreign keys — see [Constraints](/reference/constraints/) and [Relationships](/reference/relationships/). **Syntax** ```rdbms-syntax create table [if not exists] ( [constraints], ...) ``` ## Drop a table ```rdbms drop table authors ``` In advanced mode you may add `if exists` so removing a table that is not there succeeds quietly: ```sql drop table if exists authors ``` :::caution Dropping a table removes its rows as well. Use `undo` if you drop one by mistake. ::: ## Renaming a table Renaming a table is available in advanced mode: ```sql alter table authors rename to writers ``` There is no simple-mode rename verb — switch to advanced mode (or use the one-line `:` escape) to rename a table.