What is a Database?
No code in this stage. Just concepts.
Every app you use stores data somewhere. Your messages, your contacts, your order history. Where does it all live? In a database. Not a file, not a spreadsheet, but a system built to store, organize, and retrieve data fast. This stage introduces the building blocks: tables, rows, columns, and data types. No code yet, just mental models.
Definition
A database is an organized collection of structured data stored electronically. A database management system (DBMS) controls how data is stored, retrieved, and updated. MySQL is one of the most popular open-source DBMSs.
1.Tables, Rows, Columns
Each table stores one type of thing. A row is one record in a table, for example, one student. A columnis a field that every row shares, for example, name or email. Every row in a table has the same columns.
2.Data Types
Every column has a data type. The main types are:
INT(or INTEGER) - whole numbers, up to ~2.14 billionINT UNSIGNED- whole numbers, 0 to ~4.29 billion (doubles the positive range)BIGINT- very large whole numbers, up to ~9.2 × 10¹⁸ (use when IDs may exceed 2 billion)VARCHAR(n)- variable-length string, up to n charactersTEXT- variable-length string, up to 65,535 bytes (16,383 characters with utf8mb4)DATE- a calendar date (no time)DATETIME- date plus timeDECIMAL(M,D)- exact numeric data type. M is precision (total digits), D is scale (digits after decimal)BOOLEAN(alias for TINYINT(1)) - stores true or false values
3.Primary Keys
Every table needs a way to identify each row uniquely. This is the primary key, a set of columns that uniquely identifies each row. It must be a unique index that does not contain any NULL values.
4.Foreign Keys and Relationships
Tables relate to each other through foreign keys. A foreign key enforces referential integrity. It prevents pointers from becoming invalid as data is inserted, updated, and deleted. The table containing the foreign key is thechild table; the table it references is the parent table. For example, an enrollment record might store a student_idthat references the students table and a course_idthat references the courses table.
How This Relates to MasterSQL
In MasterSQL, each visitor gets a fresh database server. You can create databases, create tables, insert data, and query it all through SQL. The next stage teaches you the SQL commands to do this.
5.Why This Matters
Understanding databases is the foundation for everything else in SQL. Every application you use, from social media to online banking, stores data in a database. When you understand how data is organized in tables with rows and columns, writing queries becomes intuitive. You are simply asking the database to find, filter, or combine data that is already structured.
6.Databases in Real Life
Databases power nearly every digital service you use daily:
- Social media stores your posts, friends, and messages in tables
- Online shopping tracks products, orders, and customer addresses
- Banking records account balances, transactions, and transfers
- Email stores messages, contacts, and folders in database tables
- Healthcare manages patient records, appointments, and prescriptions
Each of these systems uses tables, rows, columns, and data types, the same concepts you are learning in this stage.
What is a primary key?
Which data type would you use for a person's age?
What does a foreign key do?
Key Takeaways
- A database holds tables. Tables hold rows and columns.
- Every column has a data type (INT, VARCHAR, DATE, etc.).
- A primary key uniquely identifies each row.
- Foreign keys create relationships between tables.
Ready to test your knowledge?
Take a Quiz