You are on page 1of 5

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 3

Lab Title: SQL and DML Commands


Student Name: Umar Mustafa Reg. No: 200365
Objective: To learn DML Commands. .
To understand the working of commands .
.
LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:
AIR University Islamabad DBS LAB

LAB TASKS
Task1:
Using the DELETE statement, delete the record for the student having name
Akram and Ahsan in the table you have created in lab 2. Also, delete the
record for the course having course code=1001.
code=1001.
CREATE TABLE Students (
Name varchar(25),
Reg_No int,
Courses varchar(255),
Course_Code int,
Offered_By varchar(255)
);
INSERT INTO Students (Name, Reg_No, Courses, Course_Code, Offered_By)
VALUES
('Ali', '01', 'DIP', '1001', 'Mr.A'),
('Umar', '02', 'DLD', '1002', 'Mr.A'),
('Junaid', '03', 'DBS', '1003', 'Mr.B'),
('Hamza', '04', 'DIP', '1002', 'Mr.C'),
('Ahmed', '05', 'MLI', '1001', 'Mr.C'),
('Akram', '06', 'ENG', '1003', 'Mr.B'),
('Ahsen', '07', 'MLI', '1004', 'Mr.A'),
('Imtiaz', '08', 'ENG', '1003', 'Mr.C'),
('Hassan', '09', 'DIP', '1001', 'Mr.A'),
('Mutahir', '10', 'DSP', '1005', 'Mr.Z');

DELETE FROM Students


WHERE Name IN ('Akram' , 'Ahsen');
DELETE FROM Students
WHERE Course_Code='1001';

SELECT * FROM Students;

Output:

2
AIR University Islamabad DBS LAB

Task2:
Sort the tables you have created in lab 2 in ascending and descending order
by their name.
CREATE TABLE Students (
Name varchar(25),
Reg_No int,
Courses varchar(255),
Course_Code int,
Offered_By varchar(255)
);
INSERT INTO Students (Name, Reg_No, Courses, Course_Code, Offered_By)
VALUES
('Ali', '01', 'DIP', '1001', 'Mr.A'),
('Umar', '02', 'DLD', '1002', 'Mr.A'),
('Junaid', '03', 'DBS', '1003', 'Mr.B'),
('Hamza', '04', 'DIP', '1002', 'Mr.C'),
('Ahmed', '05', 'MLI', '1001', 'Mr.C'),
('Akram', '06', 'ENG', '1003', 'Mr.B'),
('Ahsen', '07', 'MLI', '1004', 'Mr.A'),
('Imtiaz', '08', 'ENG', '1003', 'Mr.C'),
('Hassan', '09', 'DIP', '1001', 'Mr.A'),
('Mutahir', '10', 'DSP', '1005', 'Mr.Z');

SELECT SPACE(0) AS 'Ascending Order:';


SELECT * FROM Students
ORDER BY Name ASC;

SELECT SPACE(0) AS '';

SELECT SPACE(0) AS 'Descending Order:';


SELECT * FROM Students
ORDER BY Name DESC;

Output:

3
AIR University Islamabad DBS LAB

Task3:
For the table in lab 2, generate a query for updating the table with fully
qualified names and update the following values:
CREATE TABLE Students (
Name varchar(25),
Reg_No int,
Courses varchar(255),
Course_Code int,
Offered_By varchar(255)
);
INSERT INTO Students (Name, Reg_No, Courses, Course_Code, Offered_By)
VALUES
('Ali', '01', 'DIP', '1001', 'Mr.A'),
('Basit', '02', 'DLD', '1002', 'Mr.A'),
('Junaid', '03', 'DBS', '1003', 'Mr.B'),
('Hamza', '04', 'DIP', '1002', 'Mr.C'),
('Ahmed', '05', 'MLI', '1001', 'Mr.C'),
('Akram', '06', 'ENG', '1003', 'Mr.B'),
('Ahsen', '07', 'MLI', '1004', 'Mr.A'),
('Imtiaz', '08', 'ENG', '1003', 'Mr.C'),
('Hassan', '09', 'DIP', '1001', 'Mr.A'),
('Mutahir', '10', 'DSP', '1005', 'Mr.Z');

UPDATE Students
SET Courses='SE', Offered_By='Mr.Z'
WHERE Name='Ali';
UPDATE Students
SET Courses='CG', Offered_By='Mr.X'
WHERE Name='Basit';

select * FROM Students;

Output:

4
AIR University Islamabad DBS LAB

Learning Outcomes:
 DML is used to manipulate the data within the database. DDL is used to create and
modify database objects like tables, indexes, views, and constraints. DML is used
to perform operations on the data within those database objects.
 DDL statements are typically executed less frequently than DML statements.
 The primary purpose of DML commands is to select, insert, delete, update, and
merge data records in RDBMS.

You might also like