New! Explore our Programming Academy and AI Tutor - learn to code from scratch, free to start. Explore Now
Programming› SQL› What a Database Is

What a Database Is

💻 SQL

Understand tables, rows, columns and the difference between a database and a spreadsheet.

Lesson 1 of 9 Tutorial
0 of 9 completed

A relational database stores data in tables. Each table has a fixed set of columns and any number of rows. SQL is how you ask questions of that data.

By the end of this lesson you can:
  • Describe tables, rows and columns.
  • Explain a primary key.
  • Write your first SELECT statement.

Tables

A table models one kind of thing: students, orders or lessons. Each column has a name and a type. Each row is one record.

Keys

A primary key uniquely identifies a row. It is often an auto-incrementing number. A foreign key points to a primary key in another table, creating a relationship.

CREATE TABLE students (
    id      INT AUTO_INCREMENT PRIMARY KEY,
    name    VARCHAR(100) NOT NULL,
    level   VARCHAR(20)  NOT NULL,
    email   VARCHAR(150) UNIQUE
);

Your First Query

The asterisk means every column. Return only the columns you need in real code; it is faster and clearer.

SELECT id, name, level
FROM students;
Tip SQL keywords are not case-sensitive, but writing keywords in capitals makes queries easier to read.

Practice

  1. List the columns you would use for a books table.
  2. Explain why an email column might be UNIQUE.
  3. Write a query that returns only names from students.

Hands-on exercise

Write SQL that creates a table called courses with:
1. An auto-incrementing id as primary key.
2. A title that cannot be empty.
3. A price stored as a decimal.
4. A created_at timestamp.

Recap

Tables hold rows and columns. Primary keys identify rows, foreign keys connect tables, and SELECT asks for the columns you want.

Example

CREATE TABLE students (
    id      INT AUTO_INCREMENT PRIMARY KEY,
    name    VARCHAR(100) NOT NULL,
    level   VARCHAR(20)  NOT NULL,
    email   VARCHAR(150) UNIQUE
);

Exercises

Exercise 1. Design a table Easy
Write SQL that creates a table called courses with:
1. An auto-incrementing id as primary key.
2. A title that cannot be empty.
3. A price stored as a decimal.
4. A created_at timestamp.
SQL exercise-1.sql
Expected Output
A courses table with four columns and a primary key.

Lesson Nav

Lesson sections