A schema is the plan of your database: which tables exist, which columns they have and what kind of data each column holds. The designer above lets you sketch tables and turns them into CREATE TABLE statements. It runs in your browser and saves nothing on our server.
students.id.A type tells the database what kind of value a column holds. Picking the right one prevents silly mistakes, like storing "twelve" in an age column.
| If the column holds... | A sensible type |
|---|---|
| Whole numbers, such as a quantity | INTEGER |
| Money amounts | DECIMAL (or store whole cents as INTEGER) |
| Short text, such as a name | VARCHAR or TEXT |
| Yes or no | BOOLEAN |
| A date | DATE |
| A date and time | TIMESTAMP |
Type names vary a little between databases. SQLite, for example, is relaxed about types unless you use its stricter table options. Our guide to SQL data types for beginners explains the differences.
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE,
enrolled_on DATE
);
Read it aloud: "A students table. Each student has an id that identifies them, a name they must have, an email no one else can share, and the date they enrolled."
If you add a second table, such as enrolments, give it a column like student_id that refers to students.id. That is a foreign key. The designer generates the tables; you can add the foreign key line yourself, as shown in how to add a foreign key between two tables.
When your projects grow and speed starts to matter, the sister site databaseintegrate.com covers indexes and performance for working developers.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.