Which SQL statement generates the alias Annual Salary for the calculated column SALARY*12?

  1. SELECT ename, salary*12 ‘Annual Salary’ FROM employees;

  2. SELECT ename, salary*12 “Annual Salary” FROM employees;

  3. SELECT ename, salary*12 AS Annual Salary FROM employees;

  4. SELECT ename, salary*12 AS INITCAP(“ANNUAL SALARY”) FROM employees


Correct Option: B

AI Explanation

To generate the alias "Annual Salary" for the calculated column SALARY*12, you can use the AS keyword in the SELECT statement. Let's go through each option to determine which one is correct.

Option A) SELECT ename, salary*12 'Annual Salary' FROM employees; This option is incorrect because it uses single quotes ('') instead of double quotes ("") or square brackets ([]). In SQL, double quotes or square brackets are used to define column aliases, not single quotes.

Option B) SELECT ename, salary*12 "Annual Salary" FROM employees; This option is correct because it uses double quotes ("") to define the column alias "Annual Salary". This is the correct syntax to generate an alias in SQL.

Option C) SELECT ename, salary*12 AS Annual Salary FROM employees; This option is incorrect because it does not use proper syntax for defining the column alias. The AS keyword should be followed by the alias name without any spaces. In this case, it should be written as AS "Annual Salary".

Option D) SELECT ename, salary*12 AS INITCAP("ANNUAL SALARY") FROM employees; This option is incorrect because it tries to use the INITCAP function to format the column alias. The INITCAP function is not necessary for defining the alias and would result in a syntax error.

Based on the explanations above, the correct answer is Option B) SELECT ename, salary*12 "Annual Salary" FROM employees.

Find more quizzes: