0% found this document useful (0 votes)
7 views6 pages

MidtermSQL (8) (1)

The document is a sample SQL midterm exam containing multiple-choice questions and SQL queries related to database management concepts. It covers topics such as DDL and DML commands, SQL syntax, and specific queries to retrieve data from tables. Additionally, it includes a section on World Cup history with a table of winners and host countries.

Uploaded by

becausebeast1
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)
7 views6 pages

MidtermSQL (8) (1)

The document is a sample SQL midterm exam containing multiple-choice questions and SQL queries related to database management concepts. It covers topics such as DDL and DML commands, SQL syntax, and specific queries to retrieve data from tables. Additionally, it includes a section on World Cup history with a table of winners and host countries.

Uploaded by

becausebeast1
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/ 6

ID:____________________ Name: ________Andrew Pauk____________________________

Sample SQL midterm

1) Which of the following command is to look at the META DATA ?


a) SELECT * FROM Customers; b) DESCRIBE Customers;
c) SELECT * FROM Orders; d) INSERT INTO Customers Value (‘C006’, ‘Dubai’, 11);

2) Three DDL commands:


a) CREATE, ALTER, DELETE b) INSERT, UPDATE, DELETE
c) CREATE, UPDATE, DROP d) CREATE, ALTER, DROP
e) SELECT, CREATE, DROP

3) Four DML commands


a) CREATE, UPDATE, DELETE, SELECTb) INSERT, UPDATE, DROP, SELECT
c) CREATE, ALTER, DELETE, SELECT d) INSERT, MODIFY, DELETE, SELECT
e) INSERT, UPDATE, DELETE, SELECT

4) To change the value of a customer’s discount from 8 to 4, what command do we need to use:
a) INSERT b) SELECT c) REDUCE
d) ALTER TABLE e) UPDATE.

5) To Construct a new table (with no data) we use which Command ?


a) CREATE TABLE b) ALTER TABLE c) DROP TABLE
d) INSERT e) UPDATE

6) To Add a column to a table we use which Command ?


a) CREATE TABLE b) ALTER TABLE c) DROP TABLE
d) INSERT e) UPDATE

7) To include a new row in a table we use which Command ?


a) CREATE TABLE b) ALTER TABLE c) DROP TABLE
d) INSERT e) UPDATE

8) To remove a table from the database we use which Command ?


a) CREATE TABLE b) ALTER TABLE c) DROP TABLE
d) INSERT e) UPDATE

9) For the statement SELECT x FROM y; x can be


a) Columns of tables that exist in table y b) Tables
c) All of the above d) None of the above

10) For the statement SELECT x FROM y; y can be


a) Columns of tables that exist in table y b) Tables
d) All of the above d) None of the above

1
11) We used the DESCRIBE Customers; command to:
a) To display the data type of each column in your table is
b) Clean your database (get rid of all your tables)
c) To view the names of all your tables

12) The following commands defines, alter or remove the structure of a Table, but they do not add, modify
or remove rows from a table.
a) DDL b) DML c) Define Table Structure

13) The following commands add, modify or remove rows from a table. They do not define, alter or remove
the structure of a table
a) DDL b) DML c) modify

14) A query in MS-Access is the same as


a) A virtual table b) a view in Oracle
c) may provide simplicity because the user only sees the columns he/she needs
d) may provide security because the user only sees the columns he/she is authorized to
e) all of the above

15) When we create a new database in MS-Access, we must start our database by first:
a) Creating Queries b) Creating Tables
c) Creating Forms d) Inserting Data into the Tables

16) We have two tables: Customers and Orders. We want that every time a user logs in, they can see the
name of the customer and the sum of the orders that a customer ordered without having to type in a
query. This can be done with the following command
a) A CREATE Temporary table b) CREATE NEW TABLE ON LOGIN
c) CREATE View d) ALTER TABLE

17) To view the names of all our tables in MySQL we use the command
a) View Tables b) Show Tables c) Show Databases d) Describe All

18) CREATE, ALTER, DROP


a) DDL Commands b) DML Commands
c) DCL Commands d) Commands built to terrify students

19) INSERT, UPDATE, DELETE, SELECT


a) DDL Commands b) DML Commands
c) DCL Commands d) Commands built to terrify students

20) Which of the following actions can be done with the CREATE Command ?
a) Remove a table from a database b) Insert a new row into an existing table
c) Creates a new table d) Add a column or a Foreign Key to an existing table
e) Modify the value of a field f) Remove a row from a table

21) Which of the following statements contain a syntax error:


a) SELECT ename FROM Employees; b) SELECT ssn, city FROM Employees;
2
c) SELECT ename WHERE city = ‘Dubai’

22) Which of the following statements generates the error ‘Ambiguous column name’:
a) SELECT dname, ename FROM Employees e, Departments d WHERE d.did=e.did;
b) SELECT did, d.dname FROM Employees e, Departments d;

23) Which of the following statements contain a syntax error:


a) SELECT Departments; b) SELECT * FROM Employees;
c) SELECT * FROM Employees WHERE city = ‘Al Ain’;

Tables below are for the rest of the test


Branch
bid bname
b1 UAE
b2 Japan

Departments Employees
did dname bid ssn ename city salary did
d1 Marketing b1 s1 Sara Dubai 100000 d1
d2 Accounting b1 s2 Ahmed Al Ain 50000 d1
d3 Engineer b2 s3 Mohammed Dubai 100000 d2
s4 Hiroyuki Tokyo 75000 d3
Short Answer, write in SQL

24) Display all Departments (whole row) SELECT * FROM Departments;

25) List the name and the city of all employees SELECT ename, city FROM Employees;

26) List the Employees located in Dubai. SELECT * FROM Employees WHERE city = 'Dubai';

27) List the name of all Employees that have salary greater than 75000 SELECT ename FROM Employees
WHERE salary > 75000;

28) List the name of the employee that has the biggest salary SELECT ename FROM Employees
WHERE salary = (SELECT MAX(salary) FROM Employees);

29) List the name of the employees and their corresponding department name (result should contain 3 rows).
SELECT e.ename, d.dname
FROM Employees e
3
JOIN Departments d ON e.did = d.did;

30) List all possible combinations of the name of employees with the departments without relating the
employees to the departments (result should contain 6 rows).
SELECT e.ename, d.dname
FROM Employees e
CROSS JOIN Departments d;

31) List name of employees, name of their corresponding departments and name of their corresponding
branches.
SELECT e.ename, d.dname, b.bname
FROM Employees e
JOIN Departments d ON e.did = d.did
JOIN Branch b ON d.bid = b.bid;

32) List the department name and the sum of salary of all employees in the respective department.
SELECT d.dname, SUM(e.salary) AS total_salary

FROM Employees e

JOIN Departments d ON e.did = d.did

GROUP BY d.dname;

33) List name of Employees from the UAE branch

SELECT e.ename

FROM Employees e

JOIN DepartmenAts d ON e.did = d.did

JOIN Branch b ON d.bid = b.bid

WHERE b.bname = 'UAE';

WORLD CUP

4
Year Host Country Winner Runner Up MVP
1930 Uruguay Uruguay Argentina José Nasazzi
1934 Italy Italy Czechoslovakia Giuseppe Meazza
1938 France Italy Hungary Leônidas da Silva
1950 Brazil Uruguay Brazil Zizinho
1954 Switzerland West Germany Hungary Ferenc Puskás
1958 Sweeden Brazil Sweeden Didi
1962 Chile Brazil Czechoslovakia Garrincha
1966 England England West Germany Bobby Charlton
1970 Mexico Brazil Italy Pelé
1974 West Germany West Germany Holland Johan Cruyff
1978 Argentina Argentina Holland Mario Kempes
1982 Spain Italy Germany Paolo Rossi
1986 Mexico Argentina Germany Maradona
1990 Italy West Germany Argentina Salvatore Schillaci
1994 USA Brazil Italy Romário
1998 France France Brazil Ronaldo
2002 South Korea Brazil Germany Ronaldo
2006 Germany Italy France Zidane
2010 South Africa Spain Holland Diego Forlán
2014 Brazil Null Null Null

NATION
Country Continent
Brazil South America
Argentina South America
Uruguay South America
Italy Europe
Germany Europe
France Europe
England Europe
Spain Europe

For the tables above, write an SQL statement that

34) Lists the name of the country that won the most ?
SELECT Winner, COUNT(*) AS Win_Count
FROM WorldCups
GROUP BY Winner
ORDER BY Win_Count DESC
LIMIT 1;

35) List the year and name of the host country that won when it hosted
5
SELECT Year, HostCountry
FROM WorldCups
WHERE HostCountry = Winner;

36) List the information of all world cups in ascending order by MVP name
SELECT *
FROM WorldCups
ORDER BY MVP ASC;

37) Lists the name of the continent and how many times that continent won (two tables).
SELECT N.Continent, COUNT(*) AS Win_Count
FROM WorldCups W
JOIN Nation N ON W.Winner = N.Country
GROUP BY N.Continent;

You might also like