SQL (Structured Query Language) is the standard language for defining and manipulating relational data. Every major DBMS understands it, with small differences between products. This section uses MySQL syntax, the DBMS used in the rest of the unit.
Groups of SQL commands
Group
Purpose
Commands
DDL (Data Definition Language)
Define and change the structure of database objects
CREATE, ALTER, DROP, RENAME, TRUNCATE
DML (Data Manipulation Language)
Add, read, change and remove data
INSERT, SELECT, UPDATE, DELETE
DCL (Data Control Language)
Grant and remove permissions
GRANT, REVOKE
TCL (Transaction Control Language)
Manage transactions
COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION
MySQL data types
Type
Stores
Notes
INT
Whole numbers from −2,147,483,648 to 2,147,483,647
BIGINT for larger values
DECIMAL(p, s)
Exact decimals, e.g. DECIMAL(10, 2) for money
FLOAT/DOUBLE are approximate
CHAR(n)
Fixed-length text, up to 255 characters
Padded to length n
VARCHAR(n)
Variable-length text, n up to 65,535 (limited by the row size)
Stores only the characters used
DATE
'YYYY-MM-DD', from 1000-01-01 to 9999-12-31
e.g. '2026-11-20'
TIME
'HH:MM:SS'
DATETIME
'YYYY-MM-DD HH:MM:SS'
Years 1000 to 9999
TIMESTAMP
Date and time, stored in UTC, from 1970 to 2038-01-19
Often used for “last updated”
DDL statements
SQL · ddl_examples.sql
CREATE TABLE student ( roll_no INT PRIMARY KEY, name VARCHAR(30) NOT NULL, course VARCHAR(10), marks INT CHECK (marks BETWEEN 0 AND 100), birth_date DATE);ALTER TABLE student ADD sports VARCHAR(20); -- add a columnALTER TABLE student MODIFY name VARCHAR(50) NOT NULL; -- change a columnALTER TABLE student DROP COLUMN birth_date; -- remove a column-- DROP TABLE student; would delete the table and all its data
Constraints such as PRIMARY KEY, NOT NULL, UNIQUE, CHECK and FOREIGN KEY … REFERENCES … let the DBMS enforce the rules of the design.
DML statements
Statement
Syntax
INSERT
INSERT INTO table (col1, col2) VALUES (v1, v2);
SELECT
SELECT [DISTINCT] columns FROM table [WHERE condition] [GROUP BY cols] [HAVING condition] [ORDER BY cols [ASC | DESC]];
UPDATE
UPDATE table SET col1 = v1, col2 = v2 WHERE condition;
DELETE
DELETE FROM table WHERE condition;
Text and date values go in single quotes; numbers do not. Without a WHERE clause, UPDATE and DELETE affect every row.
DCL and TCL
SQL · dcl_tcl.sql
GRANT SELECT, INSERT ON college.student TO 'clerk'@'localhost';REVOKE INSERT ON college.student FROM 'clerk'@'localhost';START TRANSACTION;UPDATE account SET balance = balance - 500 WHERE acc_no = 1;UPDATE account SET balance = balance + 500 WHERE acc_no = 2;COMMIT; -- or ROLLBACK; to undo both updates
MySQL types: INT, DECIMAL, CHAR, VARCHAR, DATE ('YYYY-MM-DD'), DATETIME, TIMESTAMP.
Select only the columns needed; ORDER BY … DESC sorts descending.
Always use WHERE with UPDATE and DELETE.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write SQL statements to create a table product(prod_id, prod_name, price) with prod_id as primary key, insert two products, increase every price by 10 %, and display products costing more than 500.
Show worked answer
CREATE TABLE product (prod_id INT PRIMARY KEY, prod_name VARCHAR(50) NOT NULL, price DECIMAL(10, 2)); then INSERT INTO product VALUES (1, 'Keyboard', 450.00), (2, 'Monitor', 9000.00); then UPDATE product SET price = price * 1.10; (no WHERE, because every price should change) and finally SELECT prod_name, price FROM product WHERE price > 500;, which returns only Monitor 9900.00 (the keyboard’s new price, 495.00, is not above 500).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-access-using-python/sql-commands-and-mysql-data-types/ to read this page.