Microsoft SQL Server Database Quiz Questions

Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:SQL Aliases
Current Quiz Count:45
Progress
0%
Q1
True / False

SQL Aliases can only be used with SELECT statements.

Q2
True / False

Aliases defined in a SELECT statement are only visible within that statement.

Q3
True / False

You can use an alias for a table but not for a column.

Q4
True / False

Column aliases must be used in the WHERE clause.

Q5
True / False

Table aliases can be used to simplify queries with multiple joins.

Q6
True / False

The alias 't' for a table cannot be used more than once in a query.

Q7
True / False

Aliases for columns can be used in the GROUP BY clause.

Q8
True / False

An alias for a column can be a reserved SQL keyword.

Q9
True / False

You can use aliases for columns and tables in the same SQL statement.

Q10
True / False

Aliasing a column requires the AS keyword.

Q11
True / False

Table aliases are mandatory in SQL queries.

Q12
True / False

You can reference column aliases in a subquery.

Q13
True / False

Aliases defined in a CTE (Common Table Expression) are visible outside the CTE.

Q14
True / False

Column aliases can be used in the HAVING clause.

Q15
True / False

Aliasing is not allowed in SQL Server for expressions in the SELECT clause.

Q16
Single Choice

Which SQL snippet uses an alias for a column?

SQL Code
SELECT FirstName AS Name FROM Employees;
Q17
Single Choice

What is the purpose of using an alias for a table in SQL?

Q18
Single Choice

Which SQL snippet demonstrates a table alias in a join?

SQL Code
SELECT E.FirstName, D.DepartmentName
FROM Employees E
JOIN Departments D ON E.DepartmentID = D.DepartmentID;
Q19
Single Choice

Can you use column aliases in the ORDER BY clause of the same query?

Q20
Single Choice

Which of the following correctly applies an alias to both columns and tables in a query?

SQL Code
SELECT E.FirstName AS EmployeeName, D.DepartmentName
FROM Employees E
JOIN Departments D ON E.DepartmentID = D.DepartmentID;
Q21
Single Choice

Is it possible to use an alias for a derived table or subquery?

Q22
Single Choice

Which SQL snippet demonstrates using an alias for an aggregate function?

SQL Code
SELECT COUNT(*) AS TotalOrders
FROM Orders;
Q23
Single Choice

Can SQL aliases be used in the HAVING clause?

Q24
Single Choice

Which of the following correctly aliases a subquery result?

SQL Code
SELECT * FROM (
 SELECT FirstName, LastName
 FROM Employees
) AS EmployeeNames;
Q25
Single Choice

Is it possible to use the same alias for different columns in the same query?

Q26
Multiple Choice

Which SQL snippet correctly aliases a table and uses it in a JOIN?

SQL Code
SELECT O.OrderID, C.CustomerName
FROM Orders O
JOIN Customers C ON O.CustomerID = C.CustomerID;
Q27
Multiple Choice

Which SQL snippet demonstrates using aliases for both a column and a table?

SQL Code
SELECT E.FirstName AS Name, D.DepartmentName
FROM Employees AS E
JOIN Departments AS D ON E.DepartmentID = D.DepartmentID;
Q28
Multiple Choice

Which SQL snippet demonstrates the use of an alias in the GROUP BY clause?

SQL Code
SELECT DepartmentID, COUNT(*) AS EmployeeCount
FROM Employees
GROUP BY DepartmentID;
Q29
Multiple Choice

Which SQL snippet correctly aliases a subquery result and uses it in the outer query?

SQL Code
SELECT * FROM (
 SELECT ProductName, SUM(SalesAmount) AS TotalSales
 FROM Sales
 GROUP BY ProductName
) AS SalesSummary;
Q30
Multiple Choice

Which SQL snippet applies an alias to a calculated column?

SQL Code
SELECT FirstName, LastName, (Salary * 0.1) AS Bonus
FROM Employees;
Q31
Multiple Choice

Which of the following SQL snippets shows correct usage of a column alias?

SQL Code
SELECT EmployeeID, FirstName AS Name
FROM Employees;
Q32
Multiple Choice

Which SQL snippet correctly aliases a table in a JOIN operation?

SQL Code
SELECT C.CustomerName, O.OrderID
FROM Customers AS C
JOIN Orders AS O ON C.CustomerID = O.CustomerID;
Q33
Multiple Choice

Which of the following correctly uses an alias for a derived table?

SQL Code
SELECT * FROM (
 SELECT DepartmentID, COUNT(*) AS NumEmployees
 FROM Employees
 GROUP BY DepartmentID
) AS DeptEmployeeCount;
Q34
Multiple Choice

Which SQL snippet demonstrates a column alias in a calculated field?

SQL Code
SELECT Salary, (Salary * 0.2) AS Tax
FROM Employees;
Q35
Multiple Choice

Which SQL snippet demonstrates aliasing a column and a table together?

SQL Code
SELECT E.FirstName AS EmployeeName, D.DepartmentName
FROM Employees E
JOIN Departments D ON E.DepartmentID = D.DepartmentID;
Q36
Multiple Choice

Which SQL snippet applies an alias to an aggregate function and uses it in a HAVING clause?

SQL Code
SELECT DepartmentID, COUNT(*) AS TotalEmployees
FROM Employees
GROUP BY DepartmentID
HAVING COUNT(*) > 10;
Q37
Multiple Choice

Which SQL snippet uses a table alias with a derived table in a JOIN operation?

SQL Code
SELECT E.FirstName, S.SalesAmount
FROM (
 SELECT EmployeeID, SUM(SalesAmount) AS TotalSales
 FROM Sales
 GROUP BY EmployeeID
) S
JOIN Employees E ON S.EmployeeID = E.EmployeeID;
Q38
Multiple Choice

Which SQL snippet demonstrates using column aliases in an ORDER BY clause?

SQL Code
SELECT FirstName AS Name, Salary
FROM Employees
ORDER BY Name;
Q39
Multiple Choice

Which SQL snippet demonstrates the correct use of an alias in the WHERE clause?

SQL Code
SELECT FirstName, LastName
FROM Employees
WHERE (Salary * 0.1) > 5000 AS Bonus;
Q40
Multiple Choice

Which SQL snippet demonstrates the correct use of an alias with a column in the SELECT clause?

SQL Code
SELECT FirstName AS EmployeeName, Salary
FROM Employees;
Q41
Multiple Choice

Which SQL snippet correctly uses an alias for a subquery in the FROM clause?

SQL Code
SELECT AvgSales.CustomerID, AvgSales.AvgAmount
FROM (
 SELECT CustomerID, AVG(SalesAmount) AS AvgAmount
 FROM Sales
 GROUP BY CustomerID
) AS AvgSales;
Q42
Multiple Choice

Which SQL snippet uses an alias to rename a column in the result set?

SQL Code
SELECT OrderID, Quantity AS TotalQuantity
FROM OrderDetails;
Q43
Multiple Choice

Which SQL snippet demonstrates using aliases with multiple columns?

SQL Code
SELECT EmployeeID AS ID, FirstName AS Name, Salary AS AnnualSalary
FROM Employees;
Q44
Multiple Choice

Which SQL snippet shows the correct use of an alias in the GROUP BY clause?

SQL Code
SELECT DepartmentID AS DeptID, COUNT(*) AS NumEmployees
FROM Employees
GROUP BY DeptID;
Q45
Multiple Choice

Which SQL snippet correctly aliases a table and a column together in a SELECT statement?

SQL Code
SELECT E.FirstName AS EmployeeName, D.DepartmentName
FROM Employees AS E
JOIN Departments AS D ON E.DepartmentID = D.DepartmentID;