MySQL Short Notes: Complete Exam-Focused Guide for SQL & Database Preparation

 


Learn SQL commands, DBMS/RDBMS, keys, joins, functions, normalization, transactions, ACID properties, and important MySQL concepts in a simple and quick-revision format.

1. MySQL

MySQL is an open-source Relational Database Management System (RDBMS) used to store, organize, manage, and retrieve data. It uses SQL (Structured Query Language) and stores data in tables containing rows and columns.

Key points

  • Open source

  • RDBMS

  • Uses SQL

  • Cross-platform

  • Supports multiple users

  • Supports transactions

  • Supports indexes, views, procedures and triggers

  • Owned by Oracle Corporation


2. Important Basic Terms

TermExam Definition
DatabaseOrganized collection of data
DBMSSoftware used to manage databases
RDBMSDBMS based on relationships between tables
SQLLanguage used to communicate with databases
TableCollection of related data
Row/RecordOne complete data item
Column/FieldAttribute of data
QueryRequest to retrieve or manipulate data
Primary KeyUniquely identifies each record
Foreign KeyConnects one table with another


3. MySQL Architecture

MySQL follows a client-server architecture.

Client

Sends SQL commands to the server.

Examples:

  • MySQL Workbench

  • MySQL Command Line Client

  • PHP/Python/Java applications

Server

  1. Receives request

  2. Processes SQL query

  3. Accesses database

  4. Returns result

Exam trick:
Client → Request → Server → Process → Result


4. Database Commands

Create database

CREATE DATABASE school;

Show databases

SHOW DATABASES;

Select database

USE school;

Delete database

DROP DATABASE school;

DROP DATABASE removes the database and its contents.


5. Table

A table contains rows and columns.

Example:

CREATE TABLE student (
    id INT,
    name VARCHAR(50),
    age INT,
    address VARCHAR(100)
);

Remember

Column = Field/Attribute
Row = Record/Tuple


6. Important MySQL Data Types

Numeric

  • INT – integer

  • DECIMAL – exact decimal

  • FLOAT – approximate floating-point

  • DOUBLE – larger/more precise floating-point values

String

  • CHAR – fixed length

  • VARCHAR – variable length

  • TEXT – large text

Date/Time

  • DATE

  • TIME

  • DATETIME

  • YEAR

Very important

CHAR = Fixed
VARCHAR = Variable


7. Constraints

Constraints are rules applied to columns.

Main constraints:

  • PRIMARY KEY

  • FOREIGN KEY

  • NOT NULL

  • UNIQUE

  • DEFAULT

  • CHECK

  • AUTO_INCREMENT

Primary Key

  • Uniquely identifies a record

  • Cannot contain NULL

  • May contain one or multiple columns

Foreign Key

Creates a relationship between tables.

NOT NULL

Does not allow NULL.

UNIQUE

Prevents duplicate values.

DEFAULT

Provides a default value.

CHECK

Restricts values according to a condition.

AUTO_INCREMENT

Automatically generates sequential numbers.


8. SQL Command Categories

DDL — Data Definition Language

Used to define database structure.

Main commands:

CREATE
ALTER
DROP
TRUNCATE

DML — Data Manipulation Language

Used to manipulate data.

INSERT
UPDATE
DELETE

DQL — Data Query Language

Main command:

SELECT

Memory Trick

DDL = Structure
DML = Data
DQL = Query


9. Most Important SQL Commands

INSERT

Adds records.

INSERT INTO student (id, name, age)
VALUES (1, 'Ram', 18);

UPDATE

Modifies existing data.

UPDATE student
SET age = 20
WHERE id = 1;

DELETE

Deletes records.

DELETE FROM student
WHERE id = 1;

SELECT

Retrieves records.

SELECT * FROM student;

Exam warning: UPDATE or DELETE without WHERE can affect all rows.


10. WHERE Clause

Used to filter records.

SELECT * FROM student
WHERE age > 18;

Comparison operators

OperatorMeaning
=Equal
<>, !=Not equal
>Greater than
<Less than
>=Greater/equal
<=Less/equal


11. Logical Operators

AND

Both conditions must be true.

OR

At least one condition must be true.

NOT

Negates a condition.

Memory:
AND = Both
OR = Any one
NOT = Opposite


12. BETWEEN

Selects values within a range.

SELECT * FROM student
WHERE age BETWEEN 18 AND 20;


13. IN

Checks values against a list.

SELECT * FROM student
WHERE address IN ('Janakpur', 'Jaleshwar', 'Kathmandu');


14. LIKE

Used for pattern matching.

name LIKE 'A%'

Starts with A.

name LIKE '%a'

Ends with a.

name LIKE '%am%'

Contains am.

name LIKE '_am'

_ represents a single character.

Memory

% = Multiple characters
_ = One character


15. ORDER BY

Used to sort records.

Ascending:

ORDER BY age ASC;

Descending:

ORDER BY age DESC;

ASC = Ascending
DESC = Descending


16. DISTINCT

Removes duplicate results.

SELECT DISTINCT address
FROM student;


17. LIMIT

Restricts the number of returned rows.

SELECT * FROM student
LIMIT 5;


18. Aggregate Functions ⭐

Very important for exams.

FunctionPurpose
COUNT()Counts records
SUM()Calculates total
AVG()Calculates average
MAX()Finds maximum
MIN()Finds minimum

Example:

SELECT COUNT(*) FROM student;

Memory Trick

COUNT → How many?
SUM → Total?
AVG → Average?
MAX → Highest?
MIN → Lowest?


19. GROUP BY

Groups records having the same value.

SELECT address, COUNT(*)
FROM student
GROUP BY address;

Used, for example, to count students by address.


20. HAVING

Filters groups created by GROUP BY.

SELECT address, COUNT(*)
FROM student
GROUP BY address
HAVING COUNT(*) > 5;

WHERE vs HAVING ⭐

WHEREHAVING
Filters rowsFilters groups
Used before groupingUsed with grouped results

Memory:
WHERE → Rows
HAVING → Groups


21. NULL

NULL means missing, unknown, or unavailable value.

Correct:

WHERE email IS NULL;

Correct:

WHERE email IS NOT NULL;

Not normally:

WHERE email = NULL;


22. Joins ⭐⭐⭐

Joins retrieve related data from multiple tables.

Main types in your notes:

  1. INNER JOIN

  2. LEFT JOIN

  3. RIGHT JOIN

  4. CROSS JOIN

INNER JOIN

Returns matching records from both tables.

LEFT JOIN

Returns all records from the left table and matching records from the right table.

RIGHT JOIN

Returns all records from the right table and matching records from the left table.

CROSS JOIN

Produces a Cartesian product.

Memory:

  • INNER = Matching

  • LEFT = All left

  • RIGHT = All right

  • CROSS = Everything with everything


23. Subquery

A query inside another query is called a subquery.

Example:

SELECT name
FROM student
WHERE age > (
    SELECT AVG(age)
    FROM student
);


24. View

A view is a virtual table based on a query.

Create:

CREATE VIEW student_view AS
SELECT id, name, age
FROM student;

Use:

SELECT * FROM student_view;

Delete:

DROP VIEW student_view;

Exam answer:
View = Virtual Table


25. Index

An index improves the speed of data retrieval.

CREATE INDEX idx_name
ON student(name);

Advantage

  • Faster searching

  • Can improve query performance

Disadvantage

  • Requires additional storage

  • Can make data modification more expensive

Memory:
INDEX = Faster Search


26. Transaction

A transaction is a group of database operations treated as one unit.

Important commands:

  • COMMIT

  • ROLLBACK

  • SAVEPOINT

COMMIT

Permanently saves changes.

ROLLBACK

Undoes uncommitted changes.

SAVEPOINT

Creates a point to which a transaction can roll back.


27. ACID Properties ⭐⭐⭐

LetterMeaning
AAtomicity
CConsistency
IIsolation
DDurability

Atomicity

Transaction happens completely or not at all.

Consistency

Database remains valid.

Isolation

Transactions do not improperly interfere with each other.

Durability

Committed changes remain saved.

Memory:
ACID = Atomicity + Consistency + Isolation + Durability


28. InnoDB

InnoDB is an important MySQL storage engine.

Features mentioned in the notes:

  • Supports transactions

  • Supports foreign keys

  • Supports row-level locking

  • Provides crash recovery

It is the default storage engine in modern MySQL.


29. Important Keys ⭐

Primary Key

Uniquely identifies a record.

Foreign Key

Creates a relationship between tables.

Candidate Key

Can uniquely identify records.

Alternate Key

Candidate key not selected as primary key.

Composite Key

Key made of two or more columns.

Example:

PRIMARY KEY (student_id, subject_id);


30. Database Relationships

One-to-One

One record → one related record.

One-to-Many

One record → many related records.

Example:

One Department → Many Students

Many-to-Many

Many records → many records.

Usually implemented using a junction/bridge table.

Example:

Students ↔ Subjects


31. Normalization ⭐⭐⭐

Normalization organizes data to:

  • Reduce redundancy

  • Improve data integrity

  • Prevent update anomalies

1NF

  • Atomic values

  • No repeating groups

2NF

  • Must satisfy 1NF

  • No partial dependency on part of a composite key

3NF

  • Must satisfy 2NF

  • No inappropriate transitive dependency

BCNF

A stronger form of 3NF.

Memory:
1NF → Atomic
2NF → No Partial Dependency
3NF → No Transitive Dependency


32. Stored Procedure

A stored procedure is a group of SQL statements stored in the database and executed when called.

CALL GetStudents();


33. MySQL Functions

String Functions

  • UPPER()

  • LOWER()

  • LENGTH()

  • CONCAT()

  • SUBSTRING()

  • TRIM()

Numeric Functions

  • ROUND()

  • CEIL()

  • FLOOR()

  • ABS()

  • MOD()

Date Functions

  • NOW()

  • CURDATE()

  • CURTIME()

  • YEAR()

  • MONTH()

  • DAY()


34. Trigger

A trigger is automatically executed when a specified database event occurs.

Events:

  • INSERT

  • UPDATE

  • DELETE

Memory:
Trigger = Automatic Action


35. DELETE vs TRUNCATE vs DROP ⭐⭐⭐

FeatureDELETETRUNCATEDROP
Removes rowsYesYesYes
Removes structureNoNoYes
WHEREYesNoNo
Selected rowsYesNoNo
Table remainsYesYesNo

Best memory trick

DELETE → Selected Data
TRUNCATE → All Rows
DROP → Whole Object


36. CHAR vs VARCHAR ⭐

CHARVARCHAR
Fixed lengthVariable length
Suitable for fixed-size valuesSuitable for varying-size values

Remember:
CHAR = Fixed
VARCHAR = Variable


37. DBMS vs RDBMS

DBMS

Software used to manage databases.

RDBMS

Database system based on relationships between tables and supporting relational concepts such as keys.

Examples listed in your notes include MySQL, PostgreSQL and Oracle Database.


38. SQL vs MySQL ⭐

SQL = Database language
MySQL = Database management system that uses SQL.

Easy trick

SQL = Language
MySQL = Software/RDBMS


39. Most Important Commands — One Table

CommandUse
CREATE DATABASECreate database
SHOW DATABASESShow databases
USESelect database
CREATE TABLECreate table
SHOW TABLESShow tables
DESCShow table structure
ALTER TABLEModify table
INSERTAdd data
SELECTRetrieve data
UPDATEModify data
DELETEDelete data
TRUNCATERemove all rows
DROPDelete object
ORDER BYSort data
GROUP BYGroup data
HAVINGFilter groups
JOINCombine related tables


40. 🔥 Top 20 Questions for Exam Revision

  1. What is MySQL?

  2. What is DBMS and RDBMS?

  3. What is SQL?

  4. Differentiate SQL and MySQL.

  5. What is a primary key?

  6. What is a foreign key?

  7. What is a composite key?

  8. What are DDL, DML and DQL?

  9. Differentiate DELETE, TRUNCATE and DROP.

  10. What is the use of WHERE?

  11. What is GROUP BY?

  12. Differentiate WHERE and HAVING.

  13. What are aggregate functions?

  14. What is a JOIN? Explain its types.

  15. What is a subquery?

  16. What is a view?

  17. What is an index?

  18. Explain ACID properties.

  19. What is normalization? Explain 1NF, 2NF and 3NF.

  20. What are stored procedures and triggers?

These topics correspond directly to the major exam-question areas listed in your uploaded notes.

🚀 Last-Minute Memory Sheet

MySQL → RDBMS
SQL → Language
Table → Rows + Columns
Primary Key → Unique Identity
Foreign Key → Relationship
DDL → CREATE, ALTER, DROP, TRUNCATE
DML → INSERT, UPDATE, DELETE
DQL → SELECT
WHERE → Filters Rows
GROUP BY → Makes Groups
HAVING → Filters Groups
ORDER BY → Sorts
LIKE → Pattern Matching
% → Multiple Characters
_ → One Character
JOIN → Combines Tables
VIEW → Virtual Table
INDEX → Faster Searching
TRANSACTION → Unit of Work
ACID → Atomicity, Consistency, Isolation, Durability
1NF → Atomic
2NF → No Partial Dependency
3NF → No Transitive Dependency
TRIGGER → Automatic Action
CHAR → Fixed
VARCHAR → Variable
DELETE → Selected Rows
TRUNCATE → All Rows
DROP → Whole Object.

Post a Comment (0)
Previous Post Next Post