0% found this document useful (0 votes)
60 views

SQL Test New

This document contains questions about SQL statements related to performing various operations on database tables like customers, orders, products and order details. The questions cover topics like creating and dropping databases and tables, inserting, updating, deleting and selecting data from the tables.

Uploaded by

ys511315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

SQL Test New

This document contains questions about SQL statements related to performing various operations on database tables like customers, orders, products and order details. The questions cover topics like creating and dropping databases and tables, inserting, updating, deleting and selecting data from the tables.

Uploaded by

ys511315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Some of the questions within the test assume that following Customers, Orders, Products and OrderDetails tables

from the Test database are available to you.

Customers table:

CustomerID CustomerName ContactName Address City PostalCode Country


1 Mary A Mary Austin 338 City Road London EC1V 2NX UK
2 KJ Karl Jung Graefestr. 2 Berlin 10967 Germany
3 Jamie_Wats James Watson 3116 Massachusetts Avenue Washington 20004 USA
… … … … … … …

Orders table:
OrderID CustomerID OrderDate
10308 5 2017-01-21
10309 80 2017-01-22
10310 97 2017-01-22
… … …

Products table:

ProductID ProductName SupplierID CategoryID Unit Price


1 Lip Gloss 1 1 2 bottles 20
2 Eyeshadow makeup 1 2 1 box 10
3 Lip Balm 2 1 1 bottle 5
… … … … … …

OrderDetails table:

OrderDetailID OrderID ProductID Quantity


1 12508 5 1
2 12508 6 10
3 12509 25 50
… … … …

01
Q1) What SQL statement would you use to create SQL database named Test?

a) CREATE DBT Test;


b) CREATE Test;
c) CREATE DATABASE Test;
d) MAKE DATABASE Test;

Q2) What SQL statement would you use to remove SQL database named Test?

a) DROP DATABASE Test;


b) REMOVE Test;
c) DROP DBT Test;
d) REMOVE DATABASE Test;

Q3) Assign individual relationships that one can find in ERD (Entity Relationship Diagram) to their appropriate
descriptions.

a) 1) zero or many (optional)


b) 2) one or more (mandatory)
c) 3) one to one
d) 4) one and only one (mandatory)
e) 5) one to many (mandatory)
f) 6) many
g) 7) zero or one (optional)

Q4) Which kind of relationship best describes relationship between Products (A) and OrderDetails (B) tables?

a)
b)
c)
d)

Q5) Fulfill missing parts in SQL statement below to create Products table.

(
ProductID INT ,
ProductName VARCHAR(255),
SupplierID INT,
CategoryID INT,
Unit ,
Price
);

Q6) Primary Key is a combination of two types of constraints. Find the correct one in the list below.

a) UNIQUE & DEFAULT


b) CHECK & UNIQUE
c) UNIQUE & NOT NULL
d) CHECK & AUTO INCREMENT

Q7) Which field in the Orders table has a role of FOREIGN KEY in relation to Customers table?

a) CustomerID
b) OrderID
c) OrderDate
d) CustomerName

02
Q8) What SQL statement would you use to put a new record into the Orders table?

a) INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-05');
b) PUT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (200, 125, '2018-02-05');
c) INSERT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);
d) PUT VALUES (200, 125, '2018-02-05') INTO Orders (OrderID, CustomerID, OrderDate);

Q9) What SQL statement would you use to modify the existing record of CustomerID to 10 for OrderID #10308 in
the Orders table?

a) CHANGE SET Orders CustomerID = 10 WHERE OrderID = 10308;


b) UPDATE SET Orders CustomerID = 10 WHERE OrderID = 10308;
c) CHANGE Orders SET CustomerID = 10 WHERE OrderID = 10308;
d) UPDATE Orders SET CustomerID = 10 WHERE OrderID = 10308;

Q10) What SQL statement would you use to delete order with OrderID #10308 from the Orders table?

a) DELETE FROM Orders WHERE OrderID = 10308;


b) CUT FROM Orders WHERE OrderID = 10308;
c) MOVE Orders WHERE OrderID = 10308;
d) REMOVE FROM Orders WHERE OrderID = 10308;

Q11) What SQL statement would you use to add an Age field to the Customers table?

a) UPDATE TABLE Customers ADD Age INT;


b) ALTER TABLE Customers ADD Age INT;
c) UPDATE TABLE ADD Age INT Customers;
d) ALTER TABLE ADD Age INT Customers;

Q12) What SQL statement would you use to remove Customers table from Test database?

a) REMOVE TABLE Customers;


b) REMOVE Customers;
c) DROP Customers;
d) DROP TABLE Customers;

Q13) Fulfill missing parts in SQL statement below to extract all records from Customers table.

Customers;

Q14) Fulfill missing parts in SQL statement below to extract CustomerName and Address from Customers table.

Customers;

Q15) Fulfill missing parts in SQL statement below to extract all distinct countries from Customers table.

Country
Customers;

Q16 Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
products with price higher than 20 EUR.

Products
Price ;

03
Q17) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who have NULL values in Address field.

Customers
;

Q18) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are from Germany or UK.

Customers
Country ;

Q19) Fulfill missing parts in SQL statement below to extract all records from Customers table that will include only
those customers who are not from USA.

Customers
Country ;

Q20) Fulfill missing parts in SQL statement below to extract all records from Products table that will include only
those products that are supplied by supplier with SupplierID #1 and that belong to CategoryID #2.

Products
;

Q21) Fulfill missing parts in SQL statement below to arrange records in Products table according to Price in
descending order.

Products
;

Q22) Fulfill missing parts in SQL statement below to extract the first 50 records from Customers table.

Customers;

Q23) Fulfill missing parts in SQL statement below to find maximum Price for products listed in Products table.

Products;

Q24) What statement will you use to count number of records within Customers table?

a) SELECT ALL FROM Customers;


b) SELECT N FROM Customers;
c) SELECT COUNT(*) FROM Customers;
d) SELECT NROW FROM Customers

Q25) Fulfill missing parts in SQL statement below to find average Price for products listed in Products table.

Products;

04
Q26) Fulfill missing parts in SQL statement below to find overal number of ordered products using Quantity field in
OrderDetails table.

OrderDetails;

Q27) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“.

Customers
CustomerName ;

Q28) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
starts with letter „b“ and ends with letter „o“.

Customers
CustomerName ;

Q29) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table whose name
has letter „b“ in the second position.

Customers
CustomerName ;

Q30) Fulfill missing parts in SQL statement below to find all customers listed in the Customers table who live in
Germany, UK, and USA.

Customers
(“Germany“, “UK“, “USA“);

Q31) Fulfill missing parts in SQL statement below to find all products listed in the Products table whose price
belongs to range from 5 to 25 EUR, including the begin and end values.

Products
Price ;

Q32) What statement would you use to change temporarily name of the CustomerName field to Customer within
Customer table?

a) SELECT CustomerName AS Customer FROM Customers;


b) SELECT CustomerName ALIAS Customer FROM Customers;
c) SELECT CustomerName LIKE Customer FROM Customers;
d) SELECT CustomerName TO Customer FROM Customers;

Q33) Fulfill missing parts in SQL statement below to select all orders with existing customer information.

SELECT Orders.OrderID, Customers.CustomerName


FROM
Customers . CustomerID = Customers. CustomerID;

Q34) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.

SELECT Customers.CustomerName, Orders.OrderID


FROM
Orders .CustomerID = Orders.CustomerID;

05
Q35) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.

SELECT Customers.CustomerName, Orders.OrderID


FROM
Customers Orders.CustomerID = .CustomerID;

Q36) Fulfill missing parts in SQL statement below to select all customers and all orders.

SELECT Customers.CustomerName, Orders.OrderID


FROM
Orders Customers.CustomerID = .CustomerID;

Q37) What operator would you use to merge selects from two different tables with the same number of columns in
the same order and with similar data types?

a) JOIN
b) MERGE
c) UNITE
d) UNION

Q38) Fulfill missing parts in SQL statement below to calculate overal Quantity for each ProductID and arrange the
resulting list in descending order according to this new metric.

SELECT AS Overall_Quantity
FROM OrderDetails

Q39) Fulfill missing parts in SQL statement below to filter products whose overal Quantity is higher than 100 and
arrange the resulting list in descending order according to the overal Quantity.

SELECT AS Overall_Quantity
FROM OrderDetails

Q40) Fulfill missing parts in SQL statement below to create new field that will classify products listed in the
Products table as “Cheap“ when their Price will be lower than 10 EUR or as “Expensive“ otherwise.

SELECT ProductID, Price,

Price “Cheap”
“Expensive”
AS Price_Level
FROM Products;

06

You might also like