You are on page 1of 6

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO 2

Lab Title: SQL DDL and DML Commands


Student Name: Umar Mustafa Reg. No: 200365
Objective: To learn DDL and DML 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:
Create the following table using SQL and using the INSERT INTO command,
insert the following values in the table created.
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'),
('Maaz', '06', 'ENG', '1001', 'Mr.B'),
('Usama', '07', 'MLI', '1001', 'Mr.A'),
('Imtiaz', '08', 'ENG', '1001', 'Mr.C'),
('Hassan', '09', 'DLD', NULL, NULL),
('Mutahir', '10', NULL, NULL, NULL);

SELECT * FROM Students;

Output:

2
AIR University Islamabad DBS LAB

Task2:
Using the UPDATE statement, update the above table for 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'),
('Umar', '02', 'DLD', '1002', 'Mr.X'),
('Junaid', '03', 'DBS', '1003', 'Mr.Y'),
('Hamza', '04', 'DIP', '1002', 'Mr.X'),
('Ahmed', '05', 'MLI', '1001', 'Mr.A'),
('Maaz', '06', 'ENG', '1003', 'Mr.Y'),
('Usama', '07', 'MLI', '1004', 'Mr.H'),
('Imtiaz', '08', 'ENG', '1003', 'Mr.Y'),
('Hassan', '09', 'DIP', NULL, NULL),
('Mutahir', '10', NULL, NULL, NULL);

UPDATE Students
SET Course_Code='1001', Offered_By='Mr.A'
WHERE Reg_No='09';

UPDATE Students
SET Courses='DLD', Course_Code='1005', Offered_By='Mr.Z'
WHERE Reg_No='10';

Output:
SELECT * FROM Students;

3
AIR University Islamabad DBS LAB

Task3:
Select distinct values from the above two tables for the last three columns.

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.X'),
('Junaid', '03', 'DBS', '1003', 'Mr.Y'),
('Hamza', '04', 'DIP', '1002', 'Mr.X'),
('Ahmed', '05', 'MLI', '1001', 'Mr.A'),
('Maaz', '06', 'ENG', '1003', 'Mr.Y'),
('Usama', '07', 'MLI', '1004', 'Mr.H'),
('Imtiaz', '08', 'ENG', '1003', 'Mr.Y'),
('Hassan', '09', 'DIP', NULL, NULL),
('Mutahir', '10', NULL, NULL, NULL);

SELECT DISTINCT Courses FROM Students;


SELECT DISTINCT Course_Code FROM Students;
SELECT DISTINCT Offered_By FROM Students;

UPDATE Students
SET Course_Code='1001', Offered_By='Mr.A'
WHERE Reg_No='09';
UPDATE Students
SET Courses='DLD', Course_Code='1005', Offered_By='Mr.Z'
WHERE Reg_No='10';

SELECT DISTINCT Courses FROM Students;


SELECT DISTINCT Course_Code FROM Students;
SELECT DISTINCT Offered_By FROM Students;

4
AIR University Islamabad DBS LAB

Output:

5
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