Chapter Overview
This chapter introduces the Database Management System (DBMS), which deals with how data is stored, organized, and managed digitally instead of manually. It explains the meaning of data, information, and DBMS, along with the concepts of tables, keys, and relationships used in relational databases. The chapter also introduces MySQL, a popular open-source RDBMS, including its data types, DDL and DML commands, operators, and clauses used to create, modify, and manage data.
- Definition, importance, and applications of a database
- Difference between data, information, and DBMS
- Features, advantages, and limitations of DBMS
- RDBMS and MySQL basics
- Data types used in MySQL
- Tables, columns, fields, field names, and rows
- Primary Key, Foreign Key, and Composite Key
- Types of relationships: One-to-One, One-to-Many, Many-to-Many
- MySQL constraints
- DDL commands: CREATE, ALTER, DROP
- DML commands: INSERT, SELECT, UPDATE, DELETE
- Operators and clauses used in SQL queries
For SEE, students should be able to define key terms, write and explain SQL commands (especially CREATE, INSERT, SELECT, UPDATE, DELETE), identify primary and foreign keys, differentiate between DDL and DML, and solve simple output-based SQL query questions.
2.1 Definition, Importance, and Application of Database
Definition: A database is an organized collection of related data that can be easily accessed, managed, and updated. Information such as names, phone numbers, marks, prices, and addresses, when collected and stored in an organized way, forms a database. A database is not just a pile of data; it is arranged carefully to make searching, adding, deleting, and updating data quick and easy. Examples include a school attendance record, a library book list, or a mobile contact list.
Importance of Databases
- Organized Storage: Stores large amounts of data in a structured way.
- Quick Access: Allows easy searching and retrieval of required information.
- Easy Management: Makes adding, deleting, and updating data simpler.
- Data Security: Protects data from unauthorized access.
- Avoids Repetition (Redundancy): Reduces repetition of the same data.
- Multiple User Access: Allows many people to access and work with the same data at the same time.
Applications of Database
- Educational Institutions: Manage student records, attendance, marks, and library data.
- Banks: Handle customer accounts, transactions, loans, and ATM details.
- Hospitals: Store patient details, doctor records, medicine inventories, and billing information.
- E-Commerce Websites: Manage product listings, customer orders, payment records, and shipping details.
- Airlines and Railways: Handle ticket booking, schedules, and passenger information.
- Mobile Applications: Manage contact lists, photo galleries, and chat histories.
- Government Offices: Maintain citizen records like ID numbers, tax details, and land registration.
2.2 Data, Information, and DBMS
Data refers to raw facts or figures that have no clear meaning on their own, such as 80, Nepal, or 25/03/2025. Information is meaningful and organized data — for example, 'Rina scored 80 marks in Math' is information because we understand what it means.
DBMS (Database Management System) is software that helps to create, manage, and use databases. It helps to store, add, delete, update, and search for data, and also keeps data safe from unauthorized users. Some popular DBMS are MySQL, Oracle, Microsoft Access, and MongoDB.
Diagram showing the flow from raw Data to meaningful Information, and how a DBMS manages, stores, and secures this data.
Features of DBMS
- Data Storage: Stores large amounts of data in a neat and organized way.
- Easy Data Access: Allows quick retrieval of needed data.
- Data Security: Keeps data safe from unauthorized users.
- Multiple User Support: Many people can use the same database at the same time.
- Data Backup and Recovery: Saves a copy of data and can restore it if lost.
- Data Integrity: Keeps data accurate, correct, and consistent.
- Data Sharing: Allows different users to share data safely.
- Data Independence: The database structure can be changed without changing the programs.
Advantages and Limitations of DBMS
- Advantages: Reduces data redundancy, ensures consistency, improves security, provides easy data access, supports multi-user use, maintains integrity, provides backup and recovery.
- Limitations: High cost, complex setup, requires skilled personnel, and risk of data theft if security is weak.
Recent DBMS Technology
Common DBMS technologies include Hierarchical DBMS, Network DBMS, Relational DBMS (RDBMS), Object-Oriented DBMS, Open Source DBMS, Distributed DBMS, Cloud DBMS, and In-Memory DBMS, each suited to different data storage and management needs. In this chapter, RDBMS technology (MySQL) is studied.
RDBMS (Relational Database Management System)
RDBMS is a relational database system that stores data in tables consisting of rows and columns. Each table represents an entity, and relationships can be established between tables using keys. RDBMS supports SQL commands to manage, update, and retrieve data efficiently while ensuring data integrity and security.
2.3 Data Types in MySQL Database
MySQL is an open-source relational database management system (RDBMS) that helps to store, organize, and manage data using Structured Query Language (SQL). A data type defines the kind of data that can be stored in a field of a database, such as numbers, text, or dates.
Note: In VARCHAR(50), up to 50 characters can be stored. In CHAR(5), space is added if data is less than 5 characters. DECIMAL is better than FLOAT for money values as it keeps exact value. BOOLEAN in MySQL is actually TINYINT(1), storing 1 or 0. BLOB is used when files need to be saved directly inside the database.
2.4 Tables, Columns, Field, Field Name, and Rows
Table: A table is a part of a database where data is stored in an organized way using rows and columns. Each table stores data about one particular topic. For example, a table named Student can store information about students such as their names, ages, and addresses.
Column: A column is a vertical part of a table that stores one type of information. It is also called an attribute or field. For example, in the Student table above, ID stores identification numbers, Name stores names, Age stores ages, and City stores city names.
Field: A field is the smallest unit of data in a table — a single data value stored where a row and column meet. For example, the value 'Ram' in the Name column of the first row is a field.
Field Name: A field name is the name of a column in a table, telling what kind of data is stored in it. In the Student table, ID, Name, Age, and City are field names.
Row: A row is a horizontal part of a table that stores one complete set of information, also called a record or tuple. In the Student table, Row 1 stores Ram's details, Row 2 stores Sita's details, and Row 3 stores Hari's details.
Labeled diagram of a database table showing Table, Column/Field Name, Row/Record, and Field.
2.5 Keys: Primary Key, Foreign Key, and Composite Key
In a database, keys are special columns that help organize, identify, and connect data. The three important types are Primary Key, Foreign Key, and Composite Key.
Primary Key
A Primary Key is a column or set of columns in a table that uniquely identifies each row in the table. No two rows can have the same primary key value, and it cannot be empty.
- Uniquely identifies each row in a table.
- No two rows can have the same primary key value.
- It cannot have a null (empty) value.
- It helps to quickly find and manage data in the table.
Here, ID is the Primary Key because each student has a unique ID, no two students share the same ID, and it is not empty.
Foreign Key
A Foreign Key is a column in one table that connects to the primary key of another table. It is used to create a relationship between two tables, and its value must match a value from the primary key of the other table.
- It links one table to another table.
- It holds only values present in the primary key of the other table.
- It maintains a relationship between two tables.
- It helps to keep data consistent across tables.
Here, Mark_ID is the Primary Key of the Marks table, and Student_ID is a Foreign Key that connects to the ID column in the Student table.
Diagram showing two linked tables (Student and Marks) with Primary Key and Foreign Key relationship highlighted.
Composite Key
A composite key is a combination of two or more columns used together to uniquely identify a record in a table. It is used when a single column is not enough to make a record unique.
Here, Student_ID and Course_ID together uniquely identify each record.
Diagram showing a composite key made of two columns (Student_ID and Course_ID) together uniquely identifying each record.
Introduction to Relationship
In DBMS, a relationship defines how data in one table is connected to data in another table. It is usually established using primary keys and foreign keys, which help maintain data integrity and allow data to be linked efficiently across multiple tables.
One-to-One (1:1) Relationship
In a one-to-one relationship, each record in one table is related to only one record in another table. For example, each person has only one passport, and each passport belongs to only one person.
Entity-relationship diagram showing a One-to-One relationship between Person and Passport tables.
One-to-Many (1:M) Relationship
In a one-to-many relationship, a single record in one table can be linked to many records in another table. For example, one teacher teaches many students, but each student has one teacher.
Entity-relationship diagram showing a One-to-Many relationship between Teacher and Student tables.
Many-to-Many (M:N) Relationship
In a many-to-many relationship, records in one table can relate to multiple records in another table, and vice versa. For example, each student can join many courses, and each course can have many students.
Entity-relationship diagram showing a Many-to-Many relationship between Student and Course tables.
2.6 Introduction to MySQL: Table, Queries, Reports
MySQL is a relational database management system that helps to store, manage, and organize data properly. It is free, open-source software widely used in websites, applications, and business systems. MySQL uses SQL (Structured Query Language) to create tables, store data, search data, and manage records.
- Helps to store and manage data in an organized way.
- Can handle large amounts of data easily.
- It is free and open-source software.
- Works fast and is secure for storing important information.
- Widely used in websites, online applications, and businesses.
- Supports SQL commands and relational features like tables, keys, and relationships.
Table in MySQL
A table is an object in MySQL where data is stored in rows and columns; each column has a name and data type, and each row stores one complete record. Tables are created using SQL commands. CREATE TABLE Student ( ID INT, Name VARCHAR(50), Age INT, City VARCHAR(30) );
This command creates a table named Student with four columns: ID, Name, Age, and City.
Queries in MySQL
A query is a command given to the MySQL database to work with data — to add, search, update, or delete information. SELECT * FROM Student WHERE City = 'Butwal';
This query searches the table and gives the details of students from Butwal city.
Reports in MySQL
A report is a final output of data collected from one or more tables, shown in a clear and arranged way. Reports are made using queries and tools, not directly created by SQL commands alone. SELECT * FROM Student WHERE Age > 14;
This command shows a list of students above 14 years in a report-like format.
MySQL Constraints
Constraints are rules applied to table columns to maintain the accuracy and reliability of data. They ensure that only valid and consistent data is entered into the database.
Importance of Constraints in MySQL
- Maintain data accuracy by restricting invalid values.
- Ensure data consistency across related tables.
- Prevent duplicate entries in important columns.
- Enforce relationships between tables using foreign keys.
- Make the database more secure and reliable.
- Help in error-free data entry and updates.
2.7 MySQL Commands (DDL and DML)
A command is an instruction written in SQL to perform specific tasks in a database, such as creating tables, inserting data, viewing records, updating existing records, or removing data and table structures. The two main types of commands are DDL (Data Definition Language) and DML (Data Manipulation Language).
Diagram comparing DDL commands (CREATE, ALTER, DROP) that define database structure with DML commands (INSERT, SELECT, UPDATE, DELETE) that manage data.
DDL (Data Definition Language)
DDL commands are used to define, create, manage, and delete the database structure itself, including tables, columns, data types, and indexes. Common DDL commands are CREATE, ALTER, DROP, TRUNCATE, and RENAME.
CREATE Command
The CREATE command is used to make a new database or a new table. Syntax: CREATE DATABASE database_name; Example: CREATE DATABASE SchoolDB;
CREATE TABLE Student ( ID INT PRIMARY KEY, Name VARCHAR(50), Age INT NOT NULL, City VARCHAR(50) );
This command creates a new table named Student with the given columns and constraints.
ALTER Command
The ALTER command is used to modify the structure of an existing table — to add new columns, delete existing columns, change a column's data type, or rename a column or table.
Adding a column: ALTER TABLE Student ADD Grade VARCHAR(10);
Deleting a column: ALTER TABLE Student DROP COLUMN City;
Changing a column's data type: ALTER TABLE Student MODIFY COLUMN Age VARCHAR(5);
Renaming a column: ALTER TABLE Student CHANGE COLUMN Name FullName VARCHAR(50);
DROP Command
The DROP command is used to permanently delete an entire database or table from the system. Once dropped, all data and structure are removed forever, so it must be used carefully. Syntax: DROP TABLE table_name; DROP DATABASE database_name; Example: DROP TABLE Student; DROP DATABASE SchoolDB;
DML (Data Manipulation Language)
DML commands are used to manage the data inside database tables — to add, view, modify, or delete records without affecting the table structure. Common DML commands are INSERT, SELECT, UPDATE, and DELETE.
INSERT Command
The INSERT command adds new data (records) into a table, similar to adding a new row in a spreadsheet. Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); Example: INSERT INTO Student (ID, Name, Age, City) VALUES (1, 'Ram', 18, 'Kathmandu');
SELECT Command
The SELECT command retrieves and displays data from one or more tables. It can select all columns or specific columns, and can filter using WHERE or sort using ORDER BY. SELECT * FROM table_name; SELECT column1, column2 FROM table_name;
WHERE Clause: filters records based on a condition. Only rows satisfying the condition are shown. SELECT Name, Age FROM Student WHERE Age > 17;
ORDER BY Clause: sorts the result in ascending (ASC) or descending (DESC) order. SELECT Name, Age FROM Student ORDER BY Age DESC;
LIKE Clause: searches for a pattern in a column using wildcards % (any number of characters) and _ (a single character). SELECT Name FROM Student WHERE Name LIKE 'A%';
Operators in MySQL
Clauses in MySQL
UPDATE Command
The UPDATE command modifies existing records in a table based on a given condition. The SET keyword assigns new values, and the WHERE clause decides which records to update. If WHERE is skipped, all records are updated. Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Example: UPDATE Student SET City = 'Bhaktapur' WHERE Name = 'Sita';
This updates Sita's city to Bhaktapur while leaving other records unchanged.
DELETE Command
The DELETE command removes one or more existing records from a table based on a condition. The table structure remains unchanged; only the data is removed. If the WHERE clause is omitted, all records in the table will be deleted, so it must be used carefully. Syntax: DELETE FROM table_name WHERE condition;
Example: DELETE FROM Employee WHERE Name = 'Hari';
This removes the row containing Hari from the Employee table.
Common Mistakes
- Forgetting the WHERE clause in UPDATE or DELETE, which affects all records in the table.
- Confusing DDL commands (structure) with DML commands (data).
- Using DROP when DELETE was intended, permanently removing the table structure.
- Missing quotes around text values in SQL statements (e.g., WHERE Name = Ram instead of WHERE Name = 'Ram').
- Confusing Primary Key (unique, not null, identifies a row) with Foreign Key (links to another table's primary key).
- Using the wrong data type for a field, such as INT for a name field.
- Missing semicolons at the end of SQL statements.
- Confusing CHAR (fixed-length) with VARCHAR (variable-length).
SEE Exam Tips
- Read the question carefully to identify whether it asks to define, list, differentiate, or write a program/query.
- Write definitions directly and concisely.
- Use tables for difference-based questions.
- Always write complete and correctly punctuated SQL syntax.
- Remember the exact clause order: SELECT, FROM, WHERE, ORDER BY.
- Practice identifying Primary Key and Foreign Key from sample tables.
- Clearly separate DDL and DML commands when answering.
- Label answers clearly and do not omit important keywords like SET or VALUES.
Quick Revision
- Database: an organized collection of related data.
- Data: raw facts with no meaning; Information: organized, meaningful data.
- DBMS: software to create, manage, and use databases (e.g., MySQL, Oracle, MongoDB).
- RDBMS: stores data in tables with rows and columns, linked using keys.
- Primary Key: uniquely identifies each row, cannot be NULL, no duplicates.
- Foreign Key: links to the primary key of another table.
- Composite Key: two or more columns combined to uniquely identify a record.
- Relationships: One-to-One, One-to-Many, Many-to-Many.
- DDL commands: CREATE, ALTER, DROP, TRUNCATE, RENAME (structure).
- DML commands: INSERT, SELECT, UPDATE, DELETE (data).
- Key syntax: CREATE TABLE, INSERT INTO...VALUES, SELECT...FROM...WHERE, UPDATE...SET...WHERE, DELETE FROM...WHERE.
- Common data types: INT, FLOAT, DECIMAL, VARCHAR, CHAR, TEXT, DATE, BOOLEAN, BLOB.
- Constraints: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT.
SEE Important Areas
- Definitions of Database, DBMS, RDBMS, Data, Information.
- Primary Key vs Foreign Key — definitions, features, and examples.
- Difference between DDL and DML commands.
- Writing CREATE TABLE, INSERT, SELECT (with WHERE/ORDER BY/LIKE), UPDATE, and DELETE queries.
- Identifying and explaining relationship types with examples.
- Explaining important MySQL constraints and their purposes.