Velamuvi AIAcademy

Lesson 1 of 17 · First Queries

What Is a Database?

Start learning SQL from zero. Understand what a database is, how data is stored in tables, rows and columns, and run your first SQL query in the browser.

  • 6 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • What a database is and why spreadsheets are not enough
  • How data is organised into tables, rows and columns
  • What SQL is and where it is used
  • How to run your first query

Data is everywhere

Every app you use stores information. A shop remembers its products and orders. A school remembers its students and their results. A streaming service remembers what you watched.

All of that information lives in a database: an organised collection of data that a computer can search, sort and update very quickly, even when there are millions of records.

Why not just use a spreadsheet?

A spreadsheet works well for a few hundred rows that one person looks after. It struggles when:

  • there are millions of rows
  • many people or programs need the data at the same moment
  • the data must stay correct, with no half-saved changes or mismatched records
  • you need to combine several lists, such as customers and their orders

Databases were built for exactly these problems.

Tables, rows and columns

The most common kind of database is a relational database. It stores data in tables. A table looks like a spreadsheet tab.

idnamecountryage
1Aarav SharmaIndia21
2Maria GarciaSpain27
3Chen WeiChina24
  • A table holds one kind of thing. This one holds students.
  • A row is one item: one student.
  • A column is one piece of information about every item: the name, the country, the age.

A database usually has many tables, and the tables are linked to each other. You will learn how in the module on combining tables.

What is SQL?

SQL stands for Structured Query Language. It is the language used to talk to a relational database. You write a short instruction, called a query, and the database replies with the data you asked for.

SQL has been in use since the 1970s and is still one of the most requested skills in data and AI jobs. The same core language works in all the popular database systems, such as PostgreSQL, MySQL, SQLite, SQL Server and Oracle. Learn it once and you can use it almost anywhere.

People say the name in two ways: "S-Q-L" or "sequel". Both are fine.

Your first query

This course comes with a small practice database about an online school. It has three tables:

  • students: the people learning
  • courses: what they can study
  • enrollments: which student is taking which course, and their score

Press Run to ask the database for everything in the students table.

Try it yourselfSQL
SELECT * FROM students;

You just ran a real SQL query. Read it as a sentence: "select everything from the students table". The * means "all columns".

Now look at the other two tables. You can run more than one query at a time; each ends with a semicolon.

Try it yourselfSQL
SELECT * FROM courses;

SELECT * FROM enrollments;

Reading a result

Look at the enrollments result again. Some scores say NULL. That is how a database shows a missing value: the student has not finished the course, so there is no score yet. A later lesson is all about NULL.

Also notice the columns student_id and course_id. They hold numbers, not names. Those numbers point to rows in the other two tables, which is how tables are linked.

Common mistakes

Practice exercise

Write a query that shows everything in the courses table.

Your solutionSQL
-- Show every row and every column of the courses table
Knowledge check

In a database table, what does one row represent?

Summary

  • A database is an organised collection of data that can be searched and updated quickly.
  • A relational database stores data in tables made of rows and columns.
  • SQL is the language for asking a database questions.
  • SELECT * FROM table_name; shows everything in a table.

Next: choosing exactly which columns you want.

Finished reading? Tick it off to track your progress.