Which of the following SQL statements will not execute successfully? (Choose all that apply)

  1. SELECT lname, jobid, sal, sal+500 FROM emp;

  2. SELECT lname, jobid, sal FROM emp (sal + 500);

  3. SELECT lname, jobid, sal, sal + 500 “Bonus” FROM emp;

  4. SELECT lname, jobid, sal, sal + 500 bonus FROM emp

  5. SELECT lname || to_char(sal+500) “Employee Bonus” FROM emp;

  6. SELECT lname, sal + 500 Employee Bonus FROM emp;


Correct Option: B,D,F

AI Explanation

To answer this question, we need to analyze each SQL statement and determine whether it will execute successfully or not.

A. SELECT lname, jobid, sal, sal+500 FROM emp; This statement will execute successfully because it selects the lname, jobid, sal columns from the emp table and performs the addition of sal and 500.

B. SELECT lname, jobid, sal FROM emp (sal + 500); This statement will not execute successfully because there is a syntax error. The correct syntax to perform calculations on columns is to use the SELECT statement and specify the operation directly on the column, as shown in option A.

C. SELECT lname, jobid, sal, sal + 500 "Bonus" FROM emp; This statement will execute successfully because it selects the lname, jobid, sal columns from the emp table and performs the addition of sal and 500. It also assigns the alias "Bonus" to the calculated column.

D. SELECT lname, jobid, sal, sal + 500 bonus FROM emp; This statement will not execute successfully because there is a syntax error. The column name "bonus" is not enclosed in quotes or square brackets. To include special characters or spaces in column names, they should be enclosed in quotes or square brackets.

E. SELECT lname || to_char(sal+500) "Employee Bonus" FROM emp; This statement will execute successfully because it concatenates the lname column with the result of sal+500. The to_char function is used to convert the calculated value to a character data type. It also assigns the alias "Employee Bonus" to the calculated column.

F. SELECT lname, sal + 500 Employee Bonus FROM emp; This statement will not execute successfully because there is a syntax error. The column name "Employee Bonus" should be enclosed in quotes or square brackets.

Therefore, the SQL statements that will not execute successfully are B, D, and F.

Find more quizzes: