Databases are the organised repositories where modern applications store their data. Whether it is a bank keeping customer accounts, a school keeping student records, or a shop keeping its inventory, all of them rely on database management systems. MySQL is one of the most popular open-source Relational Database Management Systems (RDBMS) in the world, widely used because it is free, fast, reliable, and based on the widely accepted Structured Query Language (SQL).
A database management system is software that allows users to create, manage, and manipulate databases. In a relational database, data is stored in the form of tables, which are made up of rows and columns. Each row represents a record, and each column represents a field or attribute of that record. The relationship between tables is what makes the system "relational".
This chapter introduces the fundamental concepts of databases and MySQL. We will learn about data, databases, DBMS, the characteristics of tables (records and fields), keys such as primary keys and foreign keys, and the common data types used in MySQL. We will also see how to connect to the MySQL server, create and use a database, and create and view a table. These fundamentals prepare the student for writing actual queries in the next chapter.
Data is the raw, unprocessed facts and figures collected from the environment, such as a student's roll number, name, and marks. Information is the meaningful result obtained after processing data, such as the average marks of a class. A database stores data in a structured way so that it can be easily processed to produce information.
A database is an organised collection of interrelated data stored together so that it can be easily accessed, managed, and updated. A Database Management System (DBMS) is the software that provides tools to create and maintain databases and to perform operations such as inserting, updating, deleting, and retrieving data.
Some examples of DBMS are MySQL, Oracle, Microsoft SQL Server, and PostgreSQL. The language used to interact with a relational DBMS is SQL, the Structured Query Language.
In the relational model, data is organised into tables (also called relations). Each table has a name and contains: - Records (Rows/Tuples): Each row represents one complete data entry. - Fields (Columns/Attributes): Each column represents one attribute of the records.
| Roll | Name | Marks | City |
|---|---|---|---|
| 1 | Aarav | 89 | Delhi |
| 2 | Bina | 94 | Mumbai |
| 3 | Chirag | 78 | Pune |
In this table, each row is a record (one student) and each column is a field (Roll, Name, Marks, City). The table's cardinality is the number of rows (3), and its degree is the number of columns (4).
A primary key is a column (or a combination of columns) whose values uniquely identify each row in a table. A primary key cannot have NULL values and cannot contain duplicates.
A candidate key is a column that qualifies to become a primary key because its values are unique and not NULL. A table may have several candidate keys, from which one is chosen as the primary key.
The candidate keys that are not chosen as the primary key are called alternate keys.
A foreign key is a column in one table that refers to the primary key of another table. It is used to establish a relationship between the two tables and ensures referential integrity.
A composite key is a primary key made up of two or more columns that together uniquely identify a row.
MySQL supports many data types. The important ones for Class 11 are:
INT: Whole numbers from about -2 billion to +2 billion.SMALLINT: Smaller range integers.DECIMAL(p, s): Exact decimal values with precision p and scale s.FLOAT / DOUBLE: Approximate floating-point numbers.BOOL / BOOLEAN: Stores TRUE (1) or FALSE (0).DATE: Stores date in YYYY-MM-DD format.TIME: Stores time in HH:MM:SS format.DATETIME: Stores both date and time.TIMESTAMP: Stores date and time for records of transactions.YEAR: Stores a year.CHAR(n): Fixed-length string of n characters.VARCHAR(n): Variable-length string up to n characters.TEXT: Large text values.On a typical installation, the MySQL server is accessed through the MySQL command-line client:
mysql -u root -p
After entering the password, the prompt changes to mysql>.
SHOW DATABASES;
CREATE DATABASE school;
USE school;
CREATE TABLE student (
roll INT PRIMARY KEY,
name VARCHAR(30),
marks DECIMAL(5,2),
city VARCHAR(20)
);
DESC student;
The DESC command displays the structure of the table, showing each column's name, data type, and whether NULL is allowed.
SHOW TABLES;
| Term | Meaning |
|---|---|
| Database | Organised collection of interrelated data |
| Table | Data stored in rows and columns |
| Record (Row) | One complete data entry |
| Field (Column) | One attribute of a record |
| Cardinality | Number of rows in a table |
| Degree | Number of columns in a table |
| Primary Key | Uniquely identifies each row |
| Foreign Key | Refers to a primary key of another table |
| Data Type | Purpose | Example |
|---|---|---|
| INT | Whole numbers | 25 |
| DECIMAL(5,2) | Exact decimals | 89.50 |
| FLOAT | Approximate decimals | 3.14 |
| DATE | Calendar date | 2024-05-01 |
| CHAR(10) | Fixed-length string | 'AB' padded |
| VARCHAR(20) | Variable-length string | 'Aarav' |
USE database; before creating tables, so tables are created in the wrong database.;.SHOW DATABASES; with SHOW TABLES;; one lists databases and the other lists tables in the current database.DESC for something other than viewing table structure.YYYY-MM-DD for the DATE type.CREATE TABLE statements with appropriate data types.A database provides an organised and reliable way to store and manage data, and MySQL is the most popular open-source RDBMS for learning relational databases. The relational model stores data in tables made of records and fields, and keys such as the primary key and foreign key guarantee uniqueness and maintain relationships between tables. Choosing correct data types and mastering basic commands like CREATE DATABASE, USE, CREATE TABLE, and DESC build the foundation for writing powerful queries. The next chapter takes these fundamentals forward to retrieving, filtering, and manipulating data using SQL.