0% found this document useful (0 votes)
80 views8 pages

Quiz 2 Version 2

The document contains multiple choice questions about SQL and database concepts. It tests knowledge of SQL statements like DROP DATABASE, ALTER TABLE, JOINs, aggregation, and constraints. Correct answers are provided for each question.

Uploaded by

07dc855dbbb4
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
0% found this document useful (0 votes)
80 views8 pages

Quiz 2 Version 2

The document contains multiple choice questions about SQL and database concepts. It tests knowledge of SQL statements like DROP DATABASE, ALTER TABLE, JOINs, aggregation, and constraints. Correct answers are provided for each question.

Uploaded by

07dc855dbbb4
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/ 8

1- Which of the following statement removes database including its related components? 0.

A. DROP DATABASE
B. DELETE DATABASE
C. REMOVE DATABASE
D. None of the mentioned

Ans : A

2- Which statement would add a column CGPA to a table Student which is already created 0.5

A. ALTER TABLE Student ADD COLUMN (CGPA NUMBER(3,1));


B. ALTER TABLE Student CGPA NUMBER(3,1);
C. ALTER TABLE Student ADD (CGPA NUMBER(3,1));
D. Both A and C

Ans : C
3- Consider we have 30 employees where 20 of them belong to different departments and
the rest don’t belong to any department. On the other hand, we have 4 departments where
each of them have employees assigned to it. How many record will result by performing left
outer join between Table Employee and Department? (Employee left join Department) 0.5
10
20
30
40

4- Consider we have 30 employees where 20 of them belong to different departments and


the rest don’t belong to any department. On the other hand, we have 4 departments where
each of them have employees assigned to it. How many record will result by performing
right outer join between Table Employee and Department? (Employee right join
Department) 0.5
10
20
30
40
5- for each supplier, get supplier names and number of project they supplied where
supplier and project not located on the same city .
select sname , COUNT(SPJ.j#)
from S,SPJ,J
where S.s#=SPJ.s# and SPJ.j#=J.j# and S.city != J.city
group by sname
incorrect choices:

select sname , COUNT(SPJ.j#)


from S,SPJ,J
where S.s#=SPJ.s# and SPJ.j#=J.j# and S.city != J.city
group by sname

select sname , COUNT(SPJ.j#)


from S,SPJ,J
where S.s#=SPJ.s# and SPJ.j#=J.j# or S.city != J.city
group by sname

select sname , COUNT(SPJ.j#)


from S,SPJ,J
where S.s#=SPJ.s# or SPJ.j#=J.j# or S.city != J.city
group by sname

6 - Given SPJ schema, Which of the following queries get the names of suppliers who supply parts for
projects located in London or Paris.

a- select sname #correct answer


from S,SPJ,J
where S.s#=SPJ.s# and J.j#=SPJ.J#
and (J.city = 'London'or J.city = 'Paris')

b- select sname
from S,SPJ,J
where S.s#=SPJ.s# and J.j#=SPJ.J#
and J.city = 'London'or J.city = 'Paris'

c- select sname
from S,SPJ,J
where S.s#=SPJ.s# and J.j#=SPJ.J#
and (J.city = 'London'and J.city = 'Paris')

d- select sname
from S,SPJ,J
where S.s#=SPJ.s# and J.j#=SPJ.J#
and (S.city = 'London'or J.city = 'Paris')

e- select sname
from S,SPJ
where S.s#=SPJ.s#
and (S.city = 'London'or S.city = 'Paris')

7-Given SPJ schema, which of these sql statements don’t violate referential integrity constraint and
entity constraint?

1- insert into SPJ values ('s1','p1','j1',300)


2- insert into SPJ values ('s6','p1','j5',300)
3- insert into SPJ values ('s2','p9','j5',300)
4- insert into SPJ values ('s1','p2','j5',300)// correct answer
8- Given SPJ schema, what’s the correct number of columns and tuples resulting from the following
query:
select *
from P,S
where P.city != S.City

Correct Answer : 9 columns, 20 Tuples


Incorrect Answers :
8 columns, 20 Tuples
9 columns, 10 Tuples
8 columns, 18 Tuples

9- For each department whose average employee salary is more than $30,000, retrieve the department
name and the number of employees working for that department.
Select dname, avg(salary) as avg_salary, count(ssn)as employeecount
From department, employee
Where dnumber=dno
group by dname
having avg(salary)>30000

incorrect choices:

Select dname, avg(salary) as avg_salary, count(ssn)as employeecount


From department, employee
Where dnumber=dno
having avg(salary)>30000
group by dname

///////////////////////////////////////////////////

Select dname, avg(salary) as avg_salary, count(ssn)as employeecount


From department, employee
Where dnumber=dno
group by dname
having avg_salary>30000
///////////////////////////////////////////////////////////

Select dname, avg(salary) as avg_salary, count(ssn)as employeecount


From department, employee
Where dnumber=dno
group by dname
having count(ssn)>30000

10- Consider the below table:


Employee_Info

ID Department Name
01 Sales Mark
02 Human Resources John
03 Marketing Suzy
04 Accounting Adam
05 Engineering Peter
NULL NULL NULL

What will be the result of following query:

SELECT ID, Department, Name


FROM Employee_Info
WHERE EXISTS (SELECT NULL)
a)
ID Department Name
01 Sales Mark
02 Human Resources John
03 Marketing Suzy
04 Accounting Adam
05 Engineering Peter
b) Error Message.
c)
ID Department Name
NULL NULL NULL
d)
ID Department Name
01 Sales Mark
02 Human Resources John
03 Marketing Suzy
04 Accounting Adam
05 Engineering Peter
NULL NULL NULL
11-You need to display the names and job IDs of those employees who currently have a
job title that is the same as their previous one. Which of the following queries will work?
a) SELECT employee_id , job_id, first_name, last_name
FROM employees
UNION
SELECT employee_id , job_id, first_name, last_name
FROM job_history;
b) SELECT employee_id , job_id, first_name, last_name
FROM employees
INTERSECT
SELECT employee_id , job_id, first_name, last_name
FROM job_history;
c) SELECT employee_id , job_id, first_name, last_name
FROM employees
UNION ALL
SELECT employee_id , job_id, first_name, last_name
FROM job_history;
d) SELECT employee_id , job_id, first_name, last_name
FROM employees
Except
SELECT employee_id , job_id, first_name, last_name
FROM job_history;
12- Given northwind schema , Get the distinct products categories shipped by 'United Package'.

Correct answer:
select distinct CategoryName
from dbo.Products,dbo.Orders,dbo.[Order Details],dbo.Shippers,dbo.Categories
where dbo.Categories.CategoryID=dbo.Products.CategoryID and
dbo.Orders.OrderID=dbo.[Order Details].OrderID and dbo.Products.ProductID=dbo.
[Order Details].ProductID and dbo.Orders.ShipVia= dbo.Shippers.ShipperID
and dbo.Shippers.CompanyName='United Package'
incorrect answers:

select distinct CategoryName


from dbo.Products,dbo.Orders,dbo.[Order Details],dbo.Shippers,dbo.Categories
where dbo.Categories.CategoryID=dbo.Products.CategoryID and
dbo.Orders.OrderID=dbo.[Order Details].OrderID and
dbo.Products.ProductID=dbo.[Order Details].ProductID
and dbo.Orders.ShipVia= dbo.Shippers.ShipperID
or dbo.Shippers.CompanyName='United Package'

select distinct CategoryName


from dbo.Products,dbo.Orders,dbo.[Order Details],dbo.Shippers,dbo.Categories
where dbo.Categories.CategoryID=dbo.Products.CategoryID or
dbo.Orders.OrderID=dbo.[Order Details].OrderID or
dbo.Products.ProductID=dbo.[Order Details].ProductID
or dbo.Orders.ShipVia= dbo.Shippers.ShipperID
and dbo.Shippers.CompanyName='United Package'

select distinct CategoryName


from dbo.Products,dbo.Orders,dbo.[Order Details],dbo.Shippers,dbo.Categories
where dbo.Categories.CategoryID=dbo.Products.CategoryID and
(dbo.Orders.OrderID=dbo.[Order Details].OrderID or
dbo.Products.ProductID=dbo.[Order Details].ProductID
or dbo.Orders.ShipVia= dbo.Shippers.ShipperID)
and dbo.Shippers.CompanyName='United Package'

select distinct CategoryName


from dbo.Products,dbo.Orders,dbo.[Order Details],dbo.Shippers,dbo.Categories
where dbo.Categories.CategoryID=dbo.Products.CategoryID and
(dbo.Orders.OrderID=dbo.[Order Details].OrderID or
dbo.Products.ProductID=dbo.[Order Details].ProductID
or dbo.Orders.ShipVia= dbo.Shippers.ShipperID)
and dbo.Shippers.CompanyName='United Package'

13-Given SPJ schema, which of the following SQL DDL query is correct for declaring S table, you must
ensure that the status column can’t be below 10 and can’t be above 40 and all the columns can’t be null.

a- create table S
(
s# varchar(5),
sname varchar(20) not null,
status int not null check (status >= 10 and status <= 40),
city varchar(20) not null,
primary key(s#)

);

b- create table S
(
s# varchar(5),
sname varchar(20) not null,
status int not null check (status >= 10 and status <= 40),
city varchar(20) not null,

);
c-create table S
(
s# varchar(5),
sname varchar(20) not null,
status int not null check (status >= 10 and status <= 40),
city varchar(20) not null,
primary key(s#),
);
d- none of the above
14- which of the following queris Return a list of distinct customers
(CustomerID,CompanyName)who has orders shipped to UK

a- select distinct customers.CustomerID,CompanyName


from dbo.Orders , Customers
where ShipCountry='UK' and Orders.CustomerID=Customers.CustomerID

b- select c.CustomerID,CompanyName
from Customers c
where exists (select * from orders where ShipCountry='UK')

c- select distinct CustomerID,CompanyName


from dbo.Orders , Customers
where ShipCountry='UK' and Orders.CustomerID=Customers.CustomerID
d- a and b

You might also like