Which of these is NOT a common SQL performance tuning technique?
Using appropriate data types for columns.
Using wildcard characters (%) at the beginning of a search pattern.
Selecting only the required columns instead of using SELECT *.
Filtering data on indexed columns whenever possible.
What is the result of a CROSS JOIN between a table with 5 rows and a table with 3 rows?
5 rows
8 rows
15 rows
3 rows
What is the purpose of the ROW_NUMBER() function in SQL?
Returns the rank of each row based on the values in a specified column.
Determines the number of rows in a result set.
Calculates the running total of a numeric column.
Assigns a unique sequential integer to each row within a partition.
You are given a table 'EmployeeHierarchy' with columns 'EmployeeID' and 'ManagerID', representing an employee hierarchy. Write a recursive SQL query to retrieve the entire hierarchy starting from the CEO (EmployeeID = 1).
SELECT EmployeeID, ManagerID FROM EmployeeHierarchy WHERE ManagerID IS NULL;
SELECT EmployeeID, ManagerID FROM EmployeeHierarchy ORDER BY ManagerID;
WITH RecursiveHierarchy AS ( SELECT EmployeeID, ManagerID FROM EmployeeHierarchy WHERE EmployeeID = 1 UNION ALL SELECT eh.EmployeeID, eh.ManagerID FROM EmployeeHierarchy eh JOIN RecursiveHierarchy rh ON eh.ManagerID = rh.EmployeeID ) SELECT * FROM RecursiveHierarchy;
SELECT EmployeeID, ManagerID FROM EmployeeHierarchy WHERE EmployeeID = 1;
You're asked to retrieve the names of all employees who earn more than the average salary of their respective departments. This necessitates calculating the average salary per department and then comparing it to individual employee salaries. Which type of subquery would be most appropriate for this scenario?
Inline View
Correlated Subquery
Non-Correlated Subquery
Scalar Subquery
You need to represent a hierarchical organization structure in a relational database table. Which approach is most suitable for querying and traversing this hierarchical data?
Using multiple tables with foreign key relationships to represent different levels
Implementing a Recursive CTE to query and navigate the hierarchy
Creating a separate table for each level of the hierarchy
Storing the entire hierarchy as a single string in a column
You are analyzing sales data and want to display the running total of sales for each month. What SQL concept would be MOST suitable for this task?
Correlated subquery with SUM() function
GROUP BY clause with SUM() aggregate function
Self join with aggregate function
Window function with SUM() OVER (ORDER BY...)
In SQL, what is the purpose of a transaction?
To optimize query performance.
To retrieve data from a database.
To create a backup of the database.
To define a unit of work that must be executed as a whole to maintain database consistency.
What does the 'Atomicity' property in ACID guarantee?
Changes made by a committed transaction are permanent.
The database remains in a consistent state before and after a transaction.
Transactions are processed in complete isolation from each other.
A transaction either completes entirely or has no effect at all.
You are joining tables 'Customers' and 'Orders' using NATURAL JOIN. Both tables have a column named 'CustomerID'. What happens during the join?
Both 'CustomerID' columns are included, potentially with duplicate data.
The join fails because column names are identical.
Only the 'CustomerID' from 'Customers' is included.
The 'CustomerID' columns are used for the join, avoiding duplicate columns in the result.