Unit 5: Introduction to SQL - Practice Quiz

INT322 — Computing System And Technologies 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is SQL mainly used for?

Introduction to SQL Easy
A. Designing computer hardware
B. Managing relational databases
C. Creating operating systems
D. Editing digital photographs

2 Which SQL command creates a new table?

DDL commands Easy
A. GRANT
B. INSERT
C. CREATE
D. SELECT

3 Which DDL command changes the structure of an existing table?

DDL commands Easy
A. ALTER
B. UPDATE
C. COMMIT
D. SELECT

4 Which SQL command adds a new row to a table?

DML commands Easy
A. ALTER
B. REVOKE
C. INSERT
D. ROLLBACK

5 Which SQL command changes existing data in a table?

DML commands Easy
A. COMMIT
B. GRANT
C. UPDATE
D. CREATE

6 Which DCL command gives a user database privileges?

DCL commands Easy
A. ROLLBACK
B. DROP
C. GRANT
D. DELETE

7 Which TCL command permanently saves the changes made in a transaction?

TCL commands Easy
A. REVOKE
B. COMMIT
C. ALTER
D. SELECT

8 Which key uniquely identifies each row in a table?

Keys and their types Easy
A. Primary key
B. Foreign key
C. Composite key
D. Secondary key

9 Which key creates a relationship by referring to a key in another table?

Keys and their types Easy
A. Candidate key
B. Foreign key
C. Primary key
D. Alternate key

10 Which aggregate function returns the smallest value in a column?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Easy
A. MAX()
B. AVG()
C. SUM()
D. MIN()

11 Which aggregate function calculates the arithmetic mean of numeric values?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Easy
A. SUM()
B. MAX()
C. COUNT()
D. AVG()

12 Which aggregate function returns the number of rows matched by a query?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Easy
A. COUNT()
B. SUM()
C. MIN()
D. MAX()

13 What does a self join do?

Self join Easy
A. Joins a table with itself
B. Joins only temporary tables
C. Joins every available database
D. Joins columns without conditions

14 Which operator is used in the matching condition of an equi join?

Equi join Easy
A. >
B. <>
C. <
D. =

15 Which rows are returned by an inner join?

Inner join Easy
A. Rows matching in both tables
B. Rows without any matching condition
C. Rows from the left table only
D. Rows from the right table only

16 What does a left outer join return?

Outer join Easy
A. All rows from both tables
B. Only rows matching both tables
C. All left rows and matching right rows
D. Only unmatched right-table rows

17 What result does a cross join produce?

Cross join Easy
A. Only rows with missing values
B. Only rows with equal keys
C. Every combination of table rows
D. Common columns from both tables

18 What is the main purpose of the GROUP BY clause?

GROUP BY clause Easy
A. To delete duplicate table rows
B. To rename columns in results
C. To arrange rows into groups
D. To assign privileges to users

19 Which clause filters groups after a GROUP BY operation?

HAVING clause Easy
A. SELECT
B. WHERE
C. HAVING
D. ORDER BY

20 Which clause sorts the rows in a query result?

ORDER BY clause Easy
A. GROUP BY
B. HAVING
C. ORDER BY
D. WHERE

21 A developer writes SELECT name FROM Student WHERE marks >= 75; without specifying how records should be scanned. Which SQL characteristic does this demonstrate?

Introduction to SQL Medium
A. SQL is a procedural language
B. SQL is a compiled language
C. SQL is a declarative language
D. SQL is a markup language

22 A populated Employee table needs a new email column without removing its existing rows. Which command is most appropriate?

DDL commands Medium
A. UPDATE Employee ADD email VARCHAR(100);
B. CREATE COLUMN email IN Employee VARCHAR(100);
C. INSERT INTO Employee email VARCHAR(100);
D. ALTER TABLE Employee ADD email VARCHAR(100);

23 Which statement removes both the TemporaryData table definition and all rows stored in it?

DDL commands Medium
A. REMOVE TABLE TemporaryData;
B. DROP TABLE TemporaryData;
C. TRUNCATE DATABASE TemporaryData;
D. DELETE TABLE TemporaryData;

24 The salary of every employee in department 4 must increase by 10%. Which statement performs the required change?

DML commands Medium
A. UPDATE Employee SET salary = salary * 1.10 WHERE dept_id = 4;
B. MODIFY Employee SET salary = salary * 1.10 WHERE dept_id = 4;
C. UPDATE Employee SET salary = salary + 10 WHERE dept_id = 4;
D. ALTER Employee SET salary = salary * 1.10 WHERE dept_id = 4;

25 User reporter should be allowed to read the Sales table but not modify it. Which command provides the required privilege?

DCL commands Medium
A. REVOKE SELECT ON Sales FROM reporter;
B. GRANT SELECT ON Sales TO reporter;
C. GRANT UPDATE ON Sales TO reporter;
D. ALLOW SELECT ON Sales FOR reporter;

26 A transaction creates savepoint before_update, performs two valid inserts, and then performs an incorrect update. Which command undoes only the work after that savepoint?

TCL commands Medium
A. ROLLBACK TRANSACTION;
B. REVOKE before_update;
C. COMMIT TO before_update;
D. ROLLBACK TO before_update;

27 In Enrollment(student_id, course_id, semester), a student may take many courses and a course may have many students. Each student can enroll in a course only once per semester. Which primary key best enforces this rule?

Keys and their types Medium
A. (student_id, course_id, semester)
B. (course_id, semester)
C. (student_id, course_id)
D. (student_id, semester)

28 The column Order.customer_id references Customer.customer_id. What type of key is Order.customer_id in the Order table?

Keys and their types Medium
A. Composite key
B. Candidate key
C. Foreign key
D. Primary key

29 A department has salary values 40000, 50000, and NULL. What does AVG(salary) return for that department?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Medium
A. NULL
B. 30000
C. 45000
D. 50000

30 Which query returns the lowest and highest product prices in a single result row?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Medium
A. SELECT MIN(price), SUM(price) FROM Product;
B. SELECT AVG(price), MAX(price) FROM Product;
C. SELECT MIN(price), MAX(price) FROM Product;
D. SELECT COUNT(price), MAX(price) FROM Product;

31 Table Employee(emp_id, name, manager_id) stores each manager's ID in the same table. Which query correctly lists each employee with the employee's manager?

Self join Medium
A. SELECT e.name, m.name FROM Employee e CROSS JOIN Employee m ON e.manager_id = m.emp_id;
B. SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.emp_id = m.manager_id;
C. SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.manager_id = m.emp_id;
D. SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.emp_id = m.emp_id;

32 Which condition makes a join between Orders and Customer an equi join?

Equi join Medium
A. Orders.customer_id > Customer.customer_id
B. Orders.customer_id BETWEEN 1 AND 10
C. Orders.customer_id = Customer.customer_id
D. Orders.customer_id <> Customer.customer_id

33 A query must return only customers who have at least one matching order. Which join should be used between Customer and Orders?

Inner join Medium
A. LEFT OUTER JOIN
B. FULL OUTER JOIN
C. INNER JOIN
D. CROSS JOIN

34 A report must list every customer, including customers who have placed no orders. Which query meets this requirement?

Outer join Medium
A. SELECT * FROM Customer c INNER JOIN Orders o ON c.id = o.customer_id;
B. SELECT * FROM Customer c CROSS JOIN Orders o;
C. SELECT * FROM Customer c RIGHT JOIN Orders o ON c.id = o.customer_id;
D. SELECT * FROM Customer c LEFT JOIN Orders o ON c.id = o.customer_id;

35 Table Size contains 6 rows and table Color contains 4 rows. How many rows are produced by Size CROSS JOIN Color?

Cross join Medium
A. rows
B. rows
C. rows
D. rows

36 Which query correctly returns the number of employees in each department?

GROUP BY clause Medium
A. SELECT dept_id, COUNT(*) FROM Employee WHERE dept_id;
B. SELECT dept_id, COUNT(*) FROM Employee HAVING dept_id;
C. SELECT dept_id, COUNT(*) FROM Employee GROUP BY dept_id;
D. SELECT dept_id, COUNT(*) FROM Employee ORDER BY dept_id;

37 Which query returns only departments whose average salary is greater than 60000?

HAVING clause Medium
A. SELECT dept_id FROM Employee GROUP BY dept_id HAVING AVG(salary) > 60000;
B. SELECT dept_id FROM Employee HAVING salary > 60000 GROUP BY dept_id;
C. SELECT dept_id FROM Employee WHERE AVG(salary) > 60000 GROUP BY dept_id;
D. SELECT dept_id FROM Employee GROUP BY dept_id WHERE AVG(salary) > 60000;

38 A product list must be sorted from highest to lowest price, with equal-priced products sorted alphabetically by name. Which clause is correct?

ORDER BY clause Medium
A. ORDER BY price ASC, name DESC
B. ORDER BY name DESC, price ASC
C. ORDER BY price DESC, name ASC
D. ORDER BY name ASC, price DESC

39 A table contains 5 rows, but bonus is NULL in 2 of them. What values are returned by COUNT(*) and COUNT(bonus)?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Medium
A. 3 and 5
B. 5 and 3
C. 3 and 3
D. 5 and 5

40 Which query calculates total sales for each region and retains only regions whose total exceeds 100000?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Medium
A. SELECT region, SUM(amount) FROM Sales HAVING amount > 100000 GROUP BY region;
B. SELECT region, SUM(amount) FROM Sales WHERE SUM(amount) > 100000 GROUP BY region;
C. SELECT region, SUM(amount) FROM Sales ORDER BY region HAVING SUM(amount) > 100000;
D. SELECT region, SUM(amount) FROM Sales GROUP BY region HAVING SUM(amount) > 100000;

41 Table T(x) contains the rows 1, 2, and NULL. Under standard SQL three-valued logic, which values are returned by SELECT x FROM T WHERE NOT (x = 1);?

Introduction to SQL Hard
A. Only NULL
B. Only 2
C. 2 and NULL
D. 1 and NULL

42 Table Child has a foreign key referencing Parent(id). What happens under standard SQL when DROP TABLE Parent RESTRICT; is executed while that foreign key exists?

DDL commands Hard
A. Both tables are dropped because RESTRICT propagates.
B. It fails because the foreign key is a dependent object.
C. The foreign key column is dropped from the child.
D. The parent is dropped while the foreign key remains valid.

43 Before the following statement, department A has salaries 100, 200, 300, and department B has salaries 50, 150. What is the total salary afterward?

UPDATE Employee AS e SET salary = salary + 10 WHERE salary < (SELECT AVG(e2.salary) FROM Employee AS e2 WHERE e2.dept = e.dept);

DML commands Hard
A. 830
B. 800
C. 810
D. 820

44 Alice grants SELECT on R to Bob with the grant option, and Bob grants it to Carol. Alice then executes REVOKE GRANT OPTION FOR SELECT ON R FROM Bob CASCADE;. What is the resulting access?

DCL commands Hard
A. Bob retains SELECT; Carol retains SELECT.
B. Bob retains SELECT; Carol loses SELECT.
C. Bob loses SELECT; Carol loses SELECT.
D. Bob loses SELECT; Carol retains SELECT.

45 Accounts A and B initially contain 500 each. A transaction executes: subtract 100 from A; create savepoint S; add 100 to B; ROLLBACK TO S; then COMMIT. What balances are committed?

TCL commands Hard
A. A = 400, B = 600
B. A = 500, B = 600
C. A = 500, B = 500
D. A = 400, B = 500

46 For relation R(A, B, C, D), the functional dependencies are , , and . Which set lists all candidate keys?

Keys and their types Hard
A. {A, B, C} only
B. {A, D} and {B, D}
C. {A, C} and {B, C}
D. {A} and {B}

47 Department has primary key dept_id and a UNIQUE NOT NULL column dept_code. Employee.dept_code is nullable. Which constraint declaration is valid under standard relational key rules?

Keys and their types Hard
A. Department.dept_code cannot be referenced because it is an alternate key.
B. Employee.dept_code must reference only Department.dept_id.
C. Employee.dept_code cannot contain NULL after becoming a foreign key.
D. Employee.dept_code may reference Department.dept_code.

48 Column v contains 10, NULL, 20, and 30. What tuple is produced by SELECT COUNT(*), COUNT(v), SUM(v), AVG(v), MIN(v), MAX(v) FROM T;?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Hard
A. (4, 4, 60, 15, 10, 30)
B. (4, 3, 60, 15, NULL, 30)
C. (4, 3, 60, 20, 10, 30)
D. (3, 3, 60, 20, 10, 30)

49 Customer A has two matching orders, while customer B has none. For each customer, a query computes COUNT(*) and COUNT(o.order_id) after a LEFT JOIN to Orders o. What pairs are returned for A and B?

Aggregate functions: MIN, MAX, SUM, AVG and COUNT Hard
A. A: (2, 1), B: (1, 0)
B. A: (2, 2), B: (0, 0)
C. A: (1, 2), B: (1, 1)
D. A: (2, 2), B: (1, 0)

50 Table Employee(id, manager_id) stores a hierarchy. Which query finds employees whose manager's manager has id = 1?

Self join Hard
A. SELECT e.id FROM Employee e JOIN Employee m ON e.manager_id = m.id JOIN Employee g ON m.manager_id = g.id WHERE g.id = 1;
B. SELECT e.id FROM Employee e JOIN Employee m ON m.manager_id = e.id JOIN Employee g ON g.manager_id = m.id WHERE g.id = 1;
C. SELECT e.id FROM Employee e JOIN Employee m ON e.manager_id = m.manager_id JOIN Employee g ON m.id = g.id WHERE g.id = 1;
D. SELECT e.id FROM Employee e JOIN Employee m ON e.id = m.id JOIN Employee g ON m.manager_id = g.manager_id WHERE g.id = 1;

51 Table A contains join-key values 1, 1, 2, and table B contains 1, 1, 1, 3. How many rows result from A JOIN B ON A.key = B.key?

Equi join Hard
A. 7
B. 6
C. 5
D. 3

52 A contains (k,v) rows (1,10), (2,NULL), (3,20). B contains (1,10), (1,NULL), (2,NULL), (3,30). How many rows result from A JOIN B ON A.k = B.k AND A.v = B.v?

Inner join Hard
A. 1
B. 3
C. 2
D. 4

53 Three employees reference departments 10, 20, and 30. Department 10 is active, department 20 is inactive, and department 30 is absent. What does the following return?

SELECT COUNT(*), COUNT(d.id) FROM Employee e LEFT JOIN Department d ON e.dept_id = d.id AND d.active = 1;

Outer join Hard
A. (2, 1)
B. (1, 1)
C. (3, 2)
D. (3, 1)

54 A contains keys 1, 1, 2, and B contains keys 1, 3, 3. How many rows are produced by A FULL OUTER JOIN B ON A.key = B.key?

Outer join Hard
A. 7
B. 4
C. 6
D. 5

55 A contains x = 1, 2, 3, and B contains y = 2, 3. How many rows remain after SELECT * FROM A CROSS JOIN B WHERE A.x < B.y;?

Cross join Hard
A. 4
B. 2
C. 6
D. 3

56 Sales rows are ('E','A',10), ('E','A',NULL), ('E','B',20), (NULL,'A',5), and (NULL,'A',15). Ignoring row order, what does SELECT region, product, COUNT(amount), SUM(amount) FROM Sales GROUP BY region, product; return?

GROUP BY clause Hard
A. [(NULL,A,2,20), (E,A,1,10), (E,B,1,20)]
B. [(NULL,A,2,20), (E,A,1,NULL), (E,B,1,20)]
C. [(NULL,A,2,20), (E,A,2,10), (E,B,1,20)]
D. [(NULL,A,1,20), (E,A,1,10), (E,B,1,20)]

57 Department A has salaries 10 and 20; department B has salary 100. What is returned by SELECT AVG(dept_avg) FROM (SELECT dept, AVG(salary) AS dept_avg FROM Employee GROUP BY dept) AS D;?

GROUP BY clause Hard
A. 43.33
B. 50.00
C. 57.50
D. 65.00

58 Product A has amounts 10, NULL; B has 5, 15; and C has NULL, NULL. Which products survive GROUP BY product HAVING COUNT(amount) = COUNT(*)?

HAVING clause Hard
A. Products A and B
B. Product B only
C. Product A only
D. Product C only

59 Table T contains amounts 10, 20, and NULL. What does SELECT COUNT(*) FROM T HAVING AVG(amount) > 12; return when no GROUP BY is present?

HAVING clause Hard
A. Three rows containing 1
B. One row containing 3
C. One row containing 2
D. No rows are returned

60 Which clause selects the three highest-paid employees deterministically, choosing the lower employee_id first whenever salaries tie?

ORDER BY clause Hard
A. ORDER BY salary DESC, employee_id DESC FETCH FIRST 3 ROWS ONLY
B. ORDER BY salary DESC, employee_id ASC FETCH FIRST 3 ROWS ONLY
C. ORDER BY salary ASC, employee_id ASC FETCH FIRST 3 ROWS ONLY
D. ORDER BY employee_id ASC, salary DESC FETCH FIRST 3 ROWS ONLY