SQL and MySQL course Β· Module 1: Introduction to databases
Tables, rows and columns
In this lesson4
Before we give the Library its first order, we must understand its structure well. Remember these three words - they will accompany you throughout your journey.
Table
A table is a single shelf - a collection of data of one kind. In our Library we will use several shelves:
ksiazki- all books,autorzy- the creators of the books,czytelnicy- people enrolled in the Library,kategorie- thematic sections,wypozyczenia- who borrowed which book and when.
Row (record)
A row is a single scroll - one entry in a table. One row in czytelnicy describes one person:
| id | imie | nazwisko | miasto |
|---|---|---|---|
| 7 | Hypatia | of Alexandria | Alexandria |
Column (field)
A column is a single field describing all rows. czytelnicy has, among others, the columns id, imie, nazwisko and miasto (the full list is on the map of the shelves). Where a row and a column meet lies a single value - e.g. the first name of one particular person. Each column has its type - e.g. text or number (more on types in the "Table Workshop" location).
Primary key (PRIMARY KEY)
Every shelf has its register of catalog numbers - a column that uniquely identifies each row. This is the primary key, most often the id column.
Thanks to the primary key:
- no two rows share the same catalog number,
- we can point to a specific scroll among thousands without mistake.
My Pinakes followed the same idea: I described every work (author, title, opening words) so that it could never be confused with another. A database goes one step further and gives every row a unique number.
Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. What is the purpose of the primary key (PRIMARY KEY), most often the id column?
2. What is true about the id column in our tables?
Hands-on tasks in the game
- Vertical ordering
Arrange the database elements from the largest to the smallest (from the whole down to a single value):
- Click in order
Click the concepts from the smallest to the largest database element: