What is an alias in SQL?
A
A duplicate table B
A temporary name given to a table or column C
A constraint D
A stored procedure
Analysis & Theory
Aliases are temporary names assigned to tables or columns for readability.
Which keyword is used to create an alias?
A
AS B
LIKE C
IN D
ON
Analysis & Theory
The AS keyword defines an alias.
What is the output column name in this query?
SELECT first_name AS name FROM employees;
A
first_name B
name C
employees D
AS
Analysis & Theory
The column alias is 'name'.
Which query creates a table alias?
A
SELECT * FROM orders TABLE o; B
SELECT * FROM orders AS o; C
SELECT * FROM AS orders o; D
SELECT orders o;
Analysis & Theory
AS o gives the table 'orders' the alias 'o'.
Why use aliases for tables?
A
To hide table names B
To shorten table names in queries C
To speed up queries D
To enforce security
Analysis & Theory
Aliases help make queries more concise, especially in joins.
Which query renames the column 'salary' to 'monthly_salary' in the results?
A
SELECT salary monthly_salary FROM employees; B
SELECT salary AS monthly_salary FROM employees; C
SELECT salary RENAME monthly_salary FROM employees; D
SELECT salary -> monthly_salary FROM employees;
Analysis & Theory
AS monthly_salary assigns the alias.
Which alias syntax is correct without using AS?
A
SELECT name AS n FROM students; B
SELECT name n FROM students; C
SELECT AS name n FROM students; D
SELECT name -> n FROM students;
Analysis & Theory
You can omit AS and simply write: column alias.
What is the purpose of this query?
SELECT o.id, c.name FROM orders o JOIN customers c ON o.customer_id = c.id;
A
Assigns aliases to columns B
Assigns aliases to tables 'orders' and 'customers' C
Filters rows D
Creates a view
Analysis & Theory
Here 'o' and 'c' are table aliases.
Which statement is TRUE about aliases?
A
Aliases are permanent names in the database B
Aliases can only be used for tables, not columns C
Aliases are only valid within the query D
Aliases require double quotes
Analysis & Theory
Aliases are temporary and only exist in the query output.
How would you alias the result of a calculation?
SELECT price * quantity AS total FROM sales;
A
AS total B
AS calculation C
AS sum D
All of the above
Analysis & Theory
You can use AS total to name the calculated column 'total'.