EXPERIMENT 4 DBMS
EXPERIMENT 4 DBMS
DML stands for Data Manipulation Language. It is a subset of SQL (Structured Query
Language) that deals with modifying and interacting with data stored in a database. DML
provides commands to insert, update, delete, and retrieve data from tables.
DML statements require Transaction Control (TCL) since any modification made to the
database is considered a transaction. Hence, DML statements must be controlled using TCL
statements like COMMIT, ROLLBACK, and SAVEPOINT.
DML Statements in SQL:
1. INSERT – Adds new records to a table.
2. SELECT – Retrieves data from a table.
3. UPDATE – Modifies existing records.
4. DELETE – Removes records from a table.
Example:
INSERT INTO visitor (student_id, visitor_id, visitor_name, visitor_contact, visitor_relation,
checkin_time, checkout_time, purpose_of_visit)
VALUES
(1001, 1, 'Rajesh Kumar', '9876543210', 'Father', '2025-03-10 10:00:00', '2025-03-10 12:00:00',
'Dropping essentials'),
(1001, 2, 'Sunita Kumar', '9823456789', 'Mother', '2025-03-11 14:00:00', '2025-03-11 16:00:00', 'Health
check-up'),
(1002, 3, 'Amit Shah', '9812345678', 'Brother', '2025-03-08 11:00:00', '2025-03-08 13:00:00', 'Casual
visit'),
(1002, 4, 'Deepak Shah', '9876504321', 'Uncle', '2025-03-12 15:30:00', '2025-03-12 17:30:00', 'Bringing
study material'),
(1005, 5, 'Priya Sharma', '9845678901', 'Sister', '2025-03-10 09:30:00', '2025-03-10 11:30:00', 'Family
visit'),
(1006, 6, 'Ramesh Singh', '9807654321', 'Guardian', '2025-03-05 10:30:00', '2025-03-05 12:00:00', 'Fee
Payment');
select * from visitor;
SELECT Statement in SQL
The SELECT statement is used to retrieve data from a table in the database. It is the most
commonly used SQL statement.
Syntax to Retrieve All Columns:
SELECT * FROM table_name;
* → Retrieves all columns from the table.
table_name → Name of the table from which data is retrieved.
Syntax to Retrieve Specific Columns:
SELECT col1, col2, col3 FROM table_name;
col1, col2, col3 → Specifies which columns to retrieve.
table_name → Name of the table from which data is retrieved.
EXAMPLE:-
select * from visitor where visitor_name='Rajesh Kumar';
UPDATE Statement in SQL
The UPDATE statement is used to modify existing records in a table.
Syntax:
UPDATE table_name
SET col1 = val1, col2 = val2, col3 = val3
WHERE condition;
table_name → Name of the table where records are updated.
col1, col2, col3 → Column names to be updated.
val1, val2, val3 → New values for the columns.
WHERE condition → Specifies which records should be updated. (If omitted, all rows will be
updated, which may not be desirable.)
EXAMPLE:-
DELETE Statement in SQL
The DELETE statement is used to remove records from a table.
Syntax:
DELETE FROM table_name WHERE condition;
table_name → Name of the table from which records will be deleted.
WHERE condition → Specifies which records to delete. (If omitted, all records in the table will
be deleted.)
EXAMPLE:-
DELETE FROM visitor
WHERE visitor_id = 5;
SELECT * FROM VISITOR;
INSERT INTO room (room_no, room_type, rent_amount, rent_status, occupancy_status,
last_inspection_date, hostel_no)
VALUES
(106, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 1);
-- Rooms for Hostel 2
(204, 'NON AC', 7050, 'not paid', 'not occupied', NULL, 2),
(205, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 2),
(206, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 2);
(305, 'NON AC', 7050, 'not paid', 'not occupied', NULL, 3),
(306, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 3);
(405, 'NON AC', 7050, 'not paid', 'not occupied', NULL, 4),
(406, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 4);
(505, 'NON AC', 7050, 'not paid', 'not occupied', NULL, 5),
(506, 'NON AC', 7000, 'not paid', 'not occupied', NULL, 5);
INSERT INTO student (student_id, student_name, gender, room_no, city, street, house_no)
VALUES
INSERT INTO student (student_id, student_name, gender, room_no, city, street, house_no)
VALUES
VALUES
(1001, '9876543210'),
(1002, '9876543211'),
(1003, '9876543212'),
(1004, '9876543213'),
(1005, '9876543214'),
(1006, '9876543215'),
(1006, '9000000000'), -- Additional contact for student 1006
(1007, '9876543216'),
(1008, '9876543217'),
(1009, '9876543218'),
(1010, '9876543219'),
(1011, '9876543220'),
(1012, '9876543221'),
(1013, '9876543222'),
(1014, '9876543223'),
(1015, '9876543224'),
(1016, '9876543225'),
(1017, '9876543226'),
(1018, '9876543227'),
(1019, '9876543228'),
(1020, '9876543229');
VALUES
(1001, 2, 'Sunita Kumar', '9823456789', 'Mother', '2025-03-11 14:00:00', '2025-03-11 16:00:00', 'Health
check-up'),
(1002, 3, 'Amit Shah', '9812345678', 'Brother', '2025-03-08 11:00:00', '2025-03-08 13:00:00', 'Casual
visit'),
(1002, 4, 'Deepak Shah', '9876504321', 'Uncle', '2025-03-12 15:30:00', '2025-03-12 17:30:00', 'Bringing
study material'),
(1005, 5, 'Priya Sharma', '9845678901', 'Sister', '2025-03-10 09:30:00', '2025-03-10 11:30:00', 'Family
visit'),
(1006, 6, 'Ramesh Singh', '9807654321', 'Guardian', '2025-03-05 10:30:00', '2025-03-05 12:00:00', 'Fee
Payment'),
(1006, 7, 'Asha Singh', '9887654321', 'Aunt', '2025-03-07 13:30:00', '2025-03-07 15:30:00', 'Delivering
parcels'),
(1010, 8, 'Anil Mehta', '9776543210', 'Family Friend', '2025-03-03 14:30:00', '2025-03-03 16:00:00',
'Meeting for career advice'),
(1012, 9, 'Vikram Gupta', '9765432100', 'Cousin', '2025-03-15 10:15:00', '2025-03-15 12:00:00', 'Friendly
visit'),
(1015, 10, 'Kavita Mehta', '9654321000', 'Mother', '2025-03-17 09:00:00', '2025-03-17 11:00:00', 'Health
check-up'),
(1015, 11, 'Rahul Mehta', '9543210001', 'Brother', '2025-03-18 13:00:00', '2025-03-18 15:00:00',
'Delivering items'),
(1018, 12, 'Dinesh Patel', '9871234567', 'Guardian', '2025-03-20 11:00:00', '2025-03-20 13:00:00',
'Document submission'),
(1020, 13, 'Suresh Iyer', '9876541230', 'Father', '2025-03-22 10:00:00', '2025-03-22 12:30:00', 'Discussing
progress'),
(1020, 14, 'Meena Iyer', '9876549876', 'Mother', '2025-03-25 14:00:00', '2025-03-25 16:00:00', 'Meeting
warden');
INSERT INTO staff (staff_id, hostel_no, staff_name, staff_salary, city, street, house_no)
VALUES
VALUES
-- Wardens
VALUES
(3002, 1),
(3004, 2),
(3008, 3),
(3012, 4),
(3015, 5),
(3018, 6),
(3019, 7);
VALUES