100% found this document useful (1 vote)
430 views10 pages

Bahria University: Lahore Campus

1. The document provides instructions for a database management systems lab midterm exam taken by Mohammad Abdul Rafeh. 2. It includes two questions - the first asks the student to perform 15 SQL queries on multiple tables, and the second asks the student to consider two tables and perform 7 queries. 3. The student provides the code to create the necessary tables, insert sample data, and writes the SQL queries to answer each question.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
430 views10 pages

Bahria University: Lahore Campus

1. The document provides instructions for a database management systems lab midterm exam taken by Mohammad Abdul Rafeh. 2. It includes two questions - the first asks the student to perform 15 SQL queries on multiple tables, and the second asks the student to consider two tables and perform 7 queries. 3. The student provides the code to create the necessary tables, insert sample data, and writes the SQL queries to answer each question.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Bahria University

Lahore Campus
Mid Term Exam
(Spring-2021 Semester)
Department of Computer Sciences

Date: 18/04/ 2021

Instructor Name: Sadia Aslam Program/Semester: BSCS 4 A


Course Code: CSL 220 Course Title: Database management System lab
Max Marks: 30 Weightage: 30%

Instructions:
Read out the Instructions carefully.
I. Attempt all questions
II. Copying from any source will be graded as zero

Name __Mohammad Abdul Rafeh Enrollment___03-134192-019____


___________________________________________________________________________________________

Question 1 15 Marks
Consider the following relations
A. Movie (movieTitle, year, length, director)
B. Stars (sid, name, age, rating, salary)
C. Producer (name, address, gender, startingYear)
D. Region (rid, movieRegion, address)
E. Studio (studioName, address)

Perform these queries.


1. Find the name of all stars
2. Display result of all producers who came into industry in 1994
3. Find the movie whose title is “boss baby”
4. Show stars age in ascending order
5. Find the movie which has maximum length
6. Find the movie which has minimum length
7. Add a new column makeup _ Artist to Movie
8. Alter the data type of stars (SID) to nvarchar (20)
9. Drop gender column of Producer
10. Change table name of stars to Star
11. Change column name of Stars(age) to Star_Age
12. List the star’s name and salary who earns over 50000.
13. List stars whose salary is between 8000 and 12000.
14. List the name of producers concatenated with the gender. Separate both fields by text “is “, and
rename the column “Producer’s Gender”
15. Show the oldest and youngest Star

Solution
CREATE DATABASE LAB_MID

CREATE TABLE MOVIE


(
movieTITLE nvarchar(15),
yearr int,
lenght nvarchar(15),
director nvarchar(20)
);

insert into MOVIE values ('Inception', 2010 ,'2 HOUR', 'CHRISTOPER NOLN' ),
('Extraction', 2020 , '1 HOURS' , 'Mike Larocca' ),
('The Matrix',1999,'3 HOUR','Joel Silver');

SELECT * FROM MOVIE

CREATE TABLE STARS


(
Sid int,
NAME nvarchar(20),
age int,
rating varchar(8),
salary int
);

INSERT INTO STARS values (1,'Tom Hanks',63,'6.4',100000),


(2,'Matt Doman',53,'8',55000),
(3,'Leonardo',46,'9',95000);

SELECT * FROM STARS;

CREATE TABLE PRODUCER


(
NAME nvarchar(25),
adddress nvarchar(40),
gender nvarchar(10),
startingyearr int
);

insert into PRODUCER values ('HAWARD HAWKS', 'STREET # 123 CALIFORNIA' , 'MALE' , 1994),
('HANK MOODY' , 'CALIFORNICATIN' ,'MALE',2007),
('KATHRYN ANN BIGELOW','SAN CARLOS , UNITED STATE' , 'FEMALE' , 1989);

SELECT * FROM PRODUCER;

CREATE TABLE REIGON


(
Rid int,
movieREGION nvarchar(20),
adddress nvarchar(30)
);

insert into REIGON values (01, 'Hollywood','USA'),


(02,'LOOYWOOD','PAKISTAN'),
(03, 'BOLYWOOD','INDIA');
SELECT * FROM REIGON

CREATE TABLE STUDIO


(
StudioNAME nvarchar(25),
Adddress nvarchar(40)
);

insert into STUDIO values ('marvel','united state of america'),


('COMICCON','CALIFORNIA');

SELECT * FROM STUDIO

--1
select name from STARS

--2

select * from PRODUCER


where startingyearr=1994;

--3
select * from movie
where movieTITLE = 'BOSS BABY';

--4
select age from stars order by age

--5

select max(lenght) from MOVIE

--6

select min(lenght) from MOVIE

--7

alter table movie


add makup_artist nvarchar(25);

select makup_artist from MOVIE

--8

alter table stars


alter column sid nvarchar(20);

--9

alter table producer


drop column gender;

--10

sp_rename 'stars','Star';

--11

sp_rename 'star.age','star_age';

--12
select name, salary from star where salary > 50000;
--13

select * from star where salary >8000 and salary<12000;

--14

select concat(name, ' is ', gender) 'NAme' , 'Gender' from PRODUCER

--15

select max(star_age ) from star as eldest

select min(star_age) from star as youngest

Screenshots
Question 2 (7 Marks)

Consider the following relations

Table 1: Department Table 2: Employee


Code name Budget
SSN Name Department

1. Select the Name of all employees, without duplicates.


2. Select all the data of employees who’s NAME have at least three characters.
3. Add a new department with a BUDGET of 40,000 and departmental CODE 11
4. Add an employee called Mary Moore, with SSN 847.
5. Delete employees from the IT department which SSN 10
6. Increase budget of Department by 10%
7. Update the department to Computer where department is Biology in the EMPLOYEE table
Solution

create table department


(
code int,
name nvarchar(25),
budget int
);
create table EMPLOYEE
(
SSN INT,
NAME NVARCHAR(20),
DEPARTMENT NVARCHAR(20)

);

--1
select distinct name from employee

--2

select * from employee where name like '_%_%_%'

--3

INSERT INTO DEPARTMENT VALUES (11,'Shipping',40000);

--4

insert into employee (name, ssn) values ('Mary Moore',847);

--5

delete from employee where DEPARTMENT='it' and ssn=10;

--6

UPDATE department
SET BUDGET = budget + BUDGET*10/100;

--7

update employee
set DEPARTMENT='Computer' where DEPARTMENT='Biology';

Screenshot
Question 3 Write SQL statements for: (8 Marks)

1. Create a table student with columns and data types: rollno int, name varchar(20), branch varchar(20);
2. Insert suitable data into the student table
3. Alter table by adding new column class varchar(20)
4. Deleting a row from the table
5. Drop column branch
6. Alter table by changing the data type of rollno to nvarchar(8).
7. Delete all the data from student table.
8. Delete the table.

Solution
--1

create table Student


(
rollno int,
name nvarchar(20),
branch varchar(20)
);
--2

insert into Student values


(1,'Rafay','Jauharabad'),
(2,'Adnan','Sargodha'),
(3,'Huzaifa','Multan');

select * from Student

--3

alter table student


add class varchar(20);

--4

delete from student where rollno=2;

--5

alter table student


drop column branch;

--6

alter table student


alter column rollno nvarchar(8);

--7

truncate table student

--8

drop table student

Screenshot

You might also like