SQL Test New
SQL Test New
Customers table:
Orders table:
OrderID CustomerID OrderDate
10308 5 2017-01-21
10309 80 2017-01-22
10310 97 2017-01-22
… … …
Products table:
OrderDetails table:
01
Q1) What SQL statement would you use to create SQL database named Test?
Q2) What SQL statement would you use to remove SQL database named Test?
Q3) Assign individual relationships that one can find in ERD (Entity Relationship Diagram) to their appropriate
descriptions.
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.
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?
Q10) What SQL statement would you use to delete order with OrderID #10308 from the Orders table?
Q11) What SQL statement would you use to add an Age field to the Customers table?
Q12) What SQL statement would you use to remove Customers table from Test database?
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?
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?
Q33) Fulfill missing parts in SQL statement below to select all orders with existing customer information.
Q34) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.
05
Q35) Fulfill missing parts in SQL statement below to select all customers and any orders they might have.
Q36) Fulfill missing parts in SQL statement below to select all customers and all orders.
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.
Price “Cheap”
“Expensive”
AS Price_Level
FROM Products;
06