wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Database final

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

Which of the following is NOT a standard SQL isolation level?

a)

Serializable

b)

Repeatable Read

c)

Read Exclusive

d)

Read Committed

2.

Analyze the statement: ALTER TABLE orders RENAME COLUMN cust_id TO customer_id;. What is its effect?

a)

Renames the 'orders' table to 'customer_id'

b)

Renames the 'cust_id' column to 'customer_id' in the 'orders' table

c)

Copies data from 'cust_id' to a new column 'customer_id'

d)

Changes the data type of the 'cust_id' column to 'customer_id'

3.

Which property of ACID transactions ensures that all parts of a transaction are treated as a single unit?

a)

Atomicity

b)

Durability

c)

Consistency

d)

Isolation

4.

Consider the statement: CREATE TABLE students (id SERIAL PRIMARY KEY, name VARCHAR(50)); What does the 'SERIAL' keyword indicate?

a)

The 'id' column will have sequential characters

b)

The 'id' column will generate random numbers

c)

The 'id' column will store serial data formats

d)

The 'id' column will auto-increment for each new record

5.

What does the following SQL query return? SELECT COUNT(DISTINCT CustomerID) FROM Orders WHERE OrderDate BETWEEN '2021-01-01' AND '2021-12-31';

a)

Total number of distinct customers who placed orders in 2021

b)

Unique customer IDs from 2021

c)

Count of all orders placed in 2021

d)

Total number of orders in 2021

6.

Which isolation level is the least restrictive, allowing the highest level of concurrency in transactions?

a)

Read Committed

b)

Repeatable Read

c)

Serializable

d)

Read Uncommitted

7.

How would you create a copy of an existing table including only its structure but no data in PostgreSQL?

a)

CREATE TABLE new_table COPY FROM old_table;

b)

CREATE TABLE new_table LIKE old_table;

c)

CREATE TABLE new_table DUPLICATE old_table;

d)

CREATE TABLE new_table AS TABLE old_table;

8.

How are SQL triggers typically used?

a)

To monitor changes in user access patterns and optimize queries.

b)

To back up data whenever a table is modified.

c)

To automate the execution of a stored procedure at a scheduled time.

d)

To perform a set of tasks before or after changes are committed to a table.

9.

Which JOIN operation can potentially return the largest number of rows?

a)

FULL OUTER JOIN

b)

INNER JOIN

c)

LEFT JOIN

d)

CROSS JOIN

10.

Consider two tables, A and B. Table A has 5 rows and table B has 3 rows. How many rows will result from a CROSS JOIN of A and B?

a)

8

b)

15

c)

3

d)

5

11.

What does the EXISTS SQL clause do?

a)

Ensures that all rows meet the specified condition

b)

Validates the existence of a database or table

c)

Tests whether a subquery returns any rows

d)

Checks for the existence of a specific value in a column

12.

How will the following query affect the output? SELECT CustomerID, COUNT() FROM Orders GROUP BY CustomerID HAVING COUNT() > 5;

a)

It will display customers with less than 5 orders

b)

It will list all customers who have more than 5 orders

c)

It will count orders for each customer

d)

It will show all orders

13.

What is the role of an INOUT parameter in a stored procedure?

a)

It is used to input values into a trigger.

b)

It is used to pass a value into the procedure and return a modified value.

c)

It allows the procedure to output multiple values.

d)

It serves as a constant value that cannot be changed.

14.

How does the REFRESH MATERIALIZED VIEW command work in SQL?

a)

It refreshes the user's view permissions on the materialized view.

b)

It updates the view's definition in the database schema.

c)

It re-executes the view's query and updates the stored data.

d)

It checks the view for any syntactical errors.

15.

Which of the following statements is true about table inheritance in PostgreSQL?

a)

A child table inherits only the data of its parent table

b)

Child tables can add their own columns in addition to inherited ones

c)

Modifications in the parent table structure do not affect child tables

d)

Child tables cannot have their own indexes

16.

Which of the following SQL statements correctly demonstrates the use of the HAVING clause?

a)

HAVING Salary > 50000 SELECT * FROM Employees

b)

SELECT COUNT(EmployeeID), Department FROM Employees GROUP BY Department HAVING COUNT(EmployeeID) > 10

c)

SELECT * FROM Employees HAVING Salary > 50000

d)

SELECT Department FROM Employees HAVING COUNT(EmployeeID) > 10

17.

What will the following query display? SELECT ProductName FROM Products WHERE Price > ANY (SELECT Price FROM Products WHERE ProductName = 'Pen');

a)

Names of all products more expensive than the pen

b)

Names of products cheaper than the pen

c)

The price of the pen

d)

Names of all products

18.

Which command is used to remove a table in PostgreSQL?

a)

DROP TABLE

b)

ERASE TABLE

c)

REMOVE TABLE

d)

DELETE TABLE

19.

What happens if you try to update a column through a view that is not part of the view's SELECT statement?

a)

The update will succeed, and the base table will be updated.

b)

The view will be automatically expanded to include the column.

c)

The update will be ignored, but no error will be thrown.

d)

The update will fail because the column is not part of the view.

20.

What is a composite index in a database?

a)

An index that includes all columns of a table.

b)

An index created on multiple columns of a table

c)

An index shared by multiple tables.

d)

A combination of a unique index and a primary index.

21.

Which SQL statement finds the total number of orders for each customer?

a)

SELECT COUNT(OrderID), CustomerID FROM Orders;

b)

SELECT CustomerID FROM Orders COUNT(OrderID);

c)

SELECT OrderID, COUNT(CustomerID) FROM Orders;

d)

SELECT CustomerID, COUNT(OrderID) FROM Orders GROUP BY CustomerID;

22.

Which SQL statement correctly performs a LEFT JOIN between "Customers" and "Orders" where some customers may not have orders?

a)

SELECT * FROM Orders LEFT JOIN Customers ON Customers.CustomerID = Orders.CustomerID

b)

SELECT * FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID

c)

SELECT * FROM Customers, Orders WHERE Customers.CustomerID = Orders.CustomerID

d)

SELECT * FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID

23.

Which SQL statement is used to start a database transaction?

a)

BEGIN TRANSACTION

b)

CREATE TRANSACTION

c)

START TRANSACTION

d)

INIT TRANSACTION

24.

In PostgreSQL, what does the following command achieve? CREATE TABLE employees_backup (LIKE employees INCLUDING ALL);

a)

Creates 'employees_backup' with additional constraints and indexes from 'employees'

b)

Renames 'employees' to 'employees_backup'

c)

Clones only the structure of 'employees' to 'employees_backup'

d)

Copies both the structure and data of 'employees' to 'employees_backup'

25.

Which SQL clause is used to filter rows after the JOIN has been performed?

a)

WHERE

b)

FILTER

c)

ON

d)

HAVING

26.

What is the primary role of 'REFERENCES' in a 'CREATE TABLE' statement in PostgreSQL?

a)

To reference a unique constraint in the same table

b)

To reference the default value of a column

c)

To create a reference to a column in the same table

d)

To establish a foreign key relationship

27.

What is a trigger in SQL?

a)

A command used to start a stored procedure.

b)

A stored procedure that runs automatically in response to certain events on a particular table or view.

c)

A tool to monitor changes in database performance.

d)

A function that triggers an alert when data is modified.

28.

Which statement about the ORDER BY clause is true?

a)

It filters the results based on a condition

b)

It sorts the result set in ascending or descending order

c)

It selects unique records

d)

It groups the result set into summary rows

29.

In PostgreSQL, how can you create a table 'department' that is a copy of an existing table 'employees'?

a)

COPY TABLE department FROM employees;

b)

CREATE TABLE department (LIKE employees);

c)

DUPLICATE TABLE employees TO department;

d)

CREATE TABLE department COPY * FROM employees;

30.

What does the RIGHT JOIN operation do?

a)

Returns all rows from the right table and matched rows from the left table.

b)

Returns all rows from the left table and matched rows from the right table.

c)

Combines all rows from both tables.

d)

Returns only matching rows from both tables.

31.

In SQL, how can EXPLAIN be used to optimize a query?

a)

It can automatically modify the query for better performance.

b)

It increases the speed of query execution.

c)

It reduces the amount of data scanned by the query.

d)

It provides an estimated cost of the query, helping to identify slow parts of the query.

32.

What is the purpose of CREATE TABLE ... INHERITS in PostgreSQL?

a)

To duplicate a table's data and structure

b)

To rename an existing table

c)

To create a backup of a table

d)

To create a table that inherits properties of another table

33.

In a LEFT JOIN operation, which table is the primary table that retains all its rows in the result set?

a)

The left table

b)

The right table

c)

Both tables

d)

Neither table

34.

What is the correct syntax to create a new table in PostgreSQL with the same indexes as an existing table?

a)

CREATE TABLE new_table AS SELECT * FROM old_table WITH INDEXES;

b)

CREATE TABLE new_table INHERIT old_table INCLUDING INDEXES;

c)

CREATE TABLE new_table (LIKE old_table INCLUDING INDEXES);

d)

CREATE TABLE new_table DUPLICATE old_table INDEXES;

35.

In SQL, which command is used to update the data in a materialized view?

a)

RENEW MATERIALIZED VIEW

b)

REBUILD MATERIALIZED VIEW

c)

UPDATE MATERIALIZED VIEW

d)

REFRESH MATERIALIZED VIEW

36.

What is a self-join in SQL?

a)

Joining a table with itself.

b)

Joining a table with its copy.

c)

Joining a table with a subquery.

d)

Joining two different tables.

37.

What is the primary benefit of using a view in a database?

a)

It speeds up data insertion.

b)

It increases query performance.

c)

It reduces storage space.

d)

It simplifies complex queries.

38.

Analyze this command: DROP TABLE IF EXISTS inventory;. What is its purpose?

a)

To delete the 'inventory' table if it does not exist

b)

To remove the 'inventory' table if it exists

c)

To create an 'inventory' table if it does not exist

d)

To rename an existing 'inventory' table

39.

What is the primary purpose of the EXPLAIN command in SQL?

a)

To fix errors in SQL queries.

b)

To optimize and rewrite inefficient queries automatically.

c)

To display the query execution plan without actually executing the query.

d)

To execute a query and provide a detailed report of the execution plan.

40.

Which type of JOIN returns only the rows that have matching values in both tables?

a)

LEFT JOIN

b)

INNER JOIN

c)

RIGHT JOIN

d)

FULL OUTER JOIN

41.

Which SQL statement finds the total number of orders for each customer?

a)

SELECT COUNT(OrderID), CustomerID FROM Orders;

b)

SELECT OrderID, COUNT (CustomerID) FROM Orders;

c)

SELECT CustomerID, COUNT (OrderID) FROM Orders GROUP BY CustomerID;

d)

SELECT CustomerID FROM Orders COUNT(OrderID);

42.

What is a composite index in a database?

a)

A combination of a unique index and a primary index.

b)

An index created on multiple columns of a table

c)

An index that includes all columns of a table.

d)

An index shared by multiple tables.

43.

In PostgreSQL, what does the following command achieve? CREATE TABLE employees_backup (LIKE employees INCLUDING ALL);

a)

Copies both the structure and data of 'employees' to 'employees_backup'

b)

Renames 'employees' to 'employees_backup'

c)

Clones only the structure of 'employees' to 'employees_backup'

d)

Creates 'employees_backup' with additional constraints and indexes from 'employees'

44.

In SQL, which command is used to update the data in a materialized view?

a)

RENEW MATERIALIZED VIEW

b)

UPDATE MATERIALIZED VIEW

c)

REFRESH MATERIALIZED VIEW

d)

REBUILD MATERIALIZED VIEW

45.

Which SQL statement correctly performs a LEFT JOIN between "Customers" and "Orders" where some customers may not have orders?

a)

SELECT * FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID

b)

SELECT * FROM Orders LEFT JOIN Customers ON Customers.CustomerID = Orders.CustomerID

c)

SELECT * FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID

d)

SELECT * FROM Customers, Orders WHERE Customers.CustomerID = Orders.CustomerID

46.

What is the primary purpose of the EXPLAIN command in SQL?

a)

To display the query execution plan without actually executing the query.

b)

To fix errors in SQL queries.

c)

To execute a query and provide a detailed report of the execution plan.

d)

To optimize and rewrite inefficient queries automatically

47.

What is the correct syntax to create a new table in PostgreSQL with the same indexes as an existing table?

a)

CREATE TABLE new_table INHERIT old_table INCLUDING INDEXES;

b)

CREATE TABLE new_table AS SELECT * FROM old_table WITH INDEXES;

c)

CREATE TABLE new_table (LIKE old_table INCLUDING INDEXES);

d)

CREATE TABLE new_table DUPLICATE old_table INDEXES;

48.

What happens if you try to update a column through a view that is not part of the view's SELECT statement?

a)

The view will be automatically expanded to include the column.

b)

The update will succeed, and the base table will be updated.

c)

The update will be ignored, but no error will be thrown.

d)

The update will fail because the column is not part of the view.

49.

In a LEFT JOIN operation, which table is the primary table that retains all its rows in the result set?

a)

The right table

b)

The left table

c)

Both tables

d)

Neither table

50.

In SQL, how can EXPLAIN be used to optimize a query?

a)

It can automatically modify the query for better performance.

b)

It provides an estimated cost of the query, helping to identify slow parts of the query.

c)

It reduces the amount of data scanned by the query.

d)

It increases the speed of query execution.

51.

What is a self-join in SQL?

a)

Joining a table with its copy.

b)

Joining a table with itself.

c)

Joining two different tables.

d)

Joining a table with a subquery.

52.

Analyze this command: DROP TABLE IF EXISTS inventory;. What is its purpose?

a)

To remove the 'inventory' table if it exists

b)

To create an 'inventory' table if it does not exist

c)

To delete the 'inventory' table if it does not exist

d)

To rename an existing 'inventory' table

53.

Which command is used to remove a table in PostgreSQL?

a)

ERASE TABLE

b)

DROP TABLE

c)

REMOVE TABLE

d)

DELETE TABLE

54.

Which of the following statements is true about table inheritance in PostgreSQL?

a)

A child table inherits only the data of its parent table

b)

Child tables cannot have their own indexes

c)

Child tables can add their own columns in addition to inherited ones

d)

Modifications in the parent table structure do not affect child tables

55.

Which SQL statement is used to start a database transaction?

a)

INIT TRANSACTION

b)

BEGIN TRANSACTION

c)

CREATE TRANSACTION

d)

START TRANSACTION

56.

Which of the following SQL statements correctly demonstrates the use of the HAVING clause?

a)

SELECT COUNT(EmployeeID), Department FROM Employees GROUP BY Department HAVING COUNT (EmployeeID) >10

b)

SELECT Department FROM Employees HAVING COUNT (EmployeelD) > 10

c)

HAVING Salary > 50000 SELECT * FROM Employees

d)

SELECT * FROM Employees HAVING Salary > 50000

57.

What is the primary benefit of using a view in a database?

a)

It increases query performance.

b)

It speeds up data insertion.

c)

It simplifies complex queries.

d)

It reduces storage space.

58.

Which type of JOIN returns only the rows that have matching values in both tables?

a)

FULL OUTER JOIN

b)

INNER JOIN

c)

LEFT JOIN

d)

RIGHT JOIN

59.

What will the following query display? SELECT ProductName FROM Products WHERE Price > ANY (SELECT Price FROM Products WHERE ProductName = 'Pen');

a)

The price of the pen

b)

Names of products cheaper than the pen

c)

Names of all products more expensive than the pen

d)

Names of all products

60.

What is the purpose of CREATE TABLE ... INHERITS in PostgreSQL?

a)

To create a table that inherits properties of another table

b)

To rename an existing table

c)

To create a backup of a table

d)

To duplicate a table's data and structure