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. Managing relational databases
B. Editing digital photographs
C. Designing computer hardware
D. Creating operating systems

2 Which SQL command creates a new table?

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

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

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

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

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

5 Which SQL command changes existing data in a table?

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

6 Which DCL command gives a user database privileges?

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

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

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

8 Which key uniquely identifies each row in a table?

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

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

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

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

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

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

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

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

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

13 What does a self join do?

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

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 without any matching condition
B. Rows from the right table only
C. Rows from the left table only
D. Rows matching in both tables

16 What does a left outer join return?

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

17 What result does a cross join produce?

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

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

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

19 Which clause filters groups after a GROUP BY operation?

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

20 Which clause sorts the rows in a query result?

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

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 compiled language
B. SQL is a procedural language
C. SQL is a markup language
D. SQL is a declarative 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. CREATE COLUMN email IN Employee VARCHAR(100);
B. UPDATE Employee ADD email VARCHAR(100);
C. ALTER TABLE Employee ADD email VARCHAR(100);
D. INSERT INTO Employee email VARCHAR(100);

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

DDL commands Medium
A. DELETE TABLE TemporaryData;
B. DROP TABLE TemporaryData;
C. REMOVE TABLE TemporaryData;
D. TRUNCATE DATABASE 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 + 10 WHERE dept_id = 4;
B. MODIFY Employee SET salary = salary * 1.10 WHERE dept_id = 4;
C. ALTER Employee SET salary = salary * 1.10 WHERE dept_id = 4;
D. UPDATE 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. GRANT UPDATE ON Sales TO reporter;
B. ALLOW SELECT ON Sales FOR reporter;
C. GRANT SELECT ON Sales TO reporter;
D. REVOKE SELECT ON Sales FROM 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 TO before_update;
B. COMMIT TO before_update;
C. REVOKE before_update;
D. ROLLBACK TRANSACTION;

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)
B. (course_id, semester)
C. (student_id, course_id, semester)
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. Primary key
B. Candidate key
C. Composite key
D. Foreign 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. 45000
B. NULL
C. 30000
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), MAX(price) FROM Product;
B. SELECT COUNT(price), MAX(price) FROM Product;
C. SELECT MIN(price), SUM(price) FROM Product;
D. SELECT AVG(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 JOIN Employee m ON e.emp_id = m.manager_id;
B. SELECT e.name, m.name FROM Employee e CROSS JOIN Employee m ON e.manager_id = m.emp_id;
C. SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.emp_id = m.emp_id;
D. SELECT e.name, m.name FROM Employee e JOIN Employee m ON e.manager_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 <> Customer.customer_id
C. Orders.customer_id BETWEEN 1 AND 10
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. FULL OUTER JOIN
B. INNER JOIN
C. CROSS JOIN
D. LEFT OUTER 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 RIGHT JOIN Orders o ON c.id = o.customer_id;
C. SELECT * FROM Customer c CROSS JOIN Orders o;
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 ORDER BY 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 WHERE 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 DESC, name ASC
B. ORDER BY name DESC, price ASC
C. ORDER BY price ASC, name DESC
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 3
B. 5 and 5
C. 3 and 5
D. 5 and 3

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 GROUP BY region HAVING SUM(amount) > 100000;
B. SELECT region, SUM(amount) FROM Sales WHERE SUM(amount) > 100000 GROUP BY region;
C. SELECT region, SUM(amount) FROM Sales HAVING amount > 100000 GROUP BY region;
D. SELECT region, SUM(amount) FROM Sales ORDER 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 2
B. 2 and NULL
C. 1 and NULL
D. Only 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. The parent is dropped while the foreign key remains valid.
B. The foreign key column is dropped from the child.
C. It fails because the foreign key is a dependent object.
D. Both tables are dropped because RESTRICT propagates.

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. 820
B. 830
C. 810
D. 800

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 loses SELECT.
B. Bob retains SELECT; Carol retains 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 = 500
B. A = 500, B = 500
C. A = 500, B = 600
D. A = 400, B = 600

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} and {B}
D. {A, C} and {B, C}

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. Employee.dept_code must reference only Department.dept_id.
B. Department.dept_code cannot be referenced because it is an alternate key.
C. Employee.dept_code may reference Department.dept_code.
D. Employee.dept_code cannot contain NULL after becoming a foreign key.

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, 20, 10, 30)
C. (4, 3, 60, 15, NULL, 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, 2), B: (1, 0)
B. A: (2, 2), B: (0, 0)
C. A: (1, 2), B: (1, 1)
D. A: (2, 1), 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.manager_id JOIN Employee g ON m.id = g.id WHERE g.id = 1;
B. 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;
C. 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;
D. 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;

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. 3
B. 7
C. 5
D. 6

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. 2
B. 1
C. 3
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. (3, 2)
B. (1, 1)
C. (2, 1)
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. 6
B. 7
C. 4
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. 3
C. 6
D. 2

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,2,10), (E,B,1,20)]
C. [(NULL,A,1,20), (E,A,1,10), (E,B,1,20)]
D. [(NULL,A,2,20), (E,A,1,NULL), (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. 65.00
B. 43.33
C. 50.00
D. 57.50

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. Product C only
B. Product B only
C. Product A only
D. Products A and B

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. No rows are returned
C. One row containing 2
D. One row containing 3

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 ASC, employee_id ASC FETCH FIRST 3 ROWS ONLY
B. ORDER BY salary DESC, employee_id DESC FETCH FIRST 3 ROWS ONLY
C. ORDER BY salary DESC, employee_id ASC FETCH FIRST 3 ROWS ONLY
D. ORDER BY employee_id ASC, salary DESC FETCH FIRST 3 ROWS ONLY