sql banner

SQL Multiple Choice Questions (MCQs) and Answers

Master SQL with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of SQL. Begin your placement preparation journey now!

Q271

Q271 Identify the error in "SELECT Name, NULLIF(Age, 30) FROM Employees WHERE Age IS NOT NULL;"

A

Change 'NULLIF' to 'ISNULL'

B

Replace 'Age, 30' with 'Age, 0'

C

Remove 'WHERE Age IS NOT NULL'

D

No error

Q272

Q272 Correct the syntax error in "SELECT NVL(Salary, 'Not Provided') FROM Contractors;"

A

Change 'NVL' to 'COALESCE'

B

Replace 'Not Provided' with '0'

C

Add 'AS SalaryStatus' for clarity

D

No error

Q273

Q273 What is incorrect in "SELECT COALESCE(FirstName, LastName, 'Unknown') FROM Authors;"?

A

Replace 'COALESCE' with 'NVL'

B

Change 'Unknown' to 'NULL'

C

Add 'AS FullName' for clarity

D

No error

Q274

Q274 In "SELECT Name, NVL2(Salary, Salary * 1.1, Salary) AS NewSalary FROM Employees;", what needs correction?

A

Change 'NVL2' to 'COALESCE'

B

Replace 'Salary * 1.1' with 'Salary + 1000'

C

Remove 'AS NewSalary'

D

No error

Q275

Q275 What is the main use of the CASE statement in SQL?

A

To execute a sequence of commands

B

To handle errors

C

To perform if-then-else type logic

D

To loop through records

Q276

Q276 What needs to be corrected in "SELECT Name, CASE WHEN Age >= 18 THEN 'Adult' ELSE 'Minor' END FROM Employees;"?

A

Change 'CASE WHEN' to 'IF'

B

Replace '>= 18' with '> 18'

C

Remove 'ELSE 'Minor''

D

No error

Q277

Q277 Identify the error in "SELECT Name, CASE Gender WHEN 'M' THEN 'Male' WHEN 'F' THEN 'Female' END AS Gender FROM Employees;"

A

Change 'CASE Gender' to 'CASE WHEN Gender'

B

Replace 'END AS Gender' with 'END'

C

Add 'ELSE 'Other''

D

No error

Q278

Q278 What needs to be corrected in "SELECT CURRENT_DATE FROM Employees;"?

A

Replace 'CURRENT_DATE' with 'GETDATE()'

B

Remove 'FROM Employees'

C

Add 'AS Today'

D

No error

Q279

Q279 Identify the error in "SELECT Name, DATEDIFF(year, HireDate, GETDATE()) AS YearsWorked FROM Employees;"

A

Change 'DATEDIFF(year, HireDate, GETDATE())' to 'DATEDIFF(day, HireDate, GETDATE())'

B

Replace 'AS YearsWorked' with 'AS DaysWorked'

C

Remove 'GETDATE()'

D

No error

Q280

Q280 Correct the syntax error in "SELECT Name, DATEADD(MONTH, 6, HireDate) FROM Employees;"

A

Change 'DATEADD' to 'DATEDIFF'

B

Replace 'MONTH, 6' with 'YEAR, 1'

C

Remove 'HireDate'

D

No error

Q281

Q281 What is incorrect in "SELECT EXTRACT(MONTH FROM OrderDate) AS OrderMonth FROM Orders;"?

A

Replace 'EXTRACT' with 'DATEPART'

B

Change 'MONTH' to 'YEAR'

C

Remove 'AS OrderMonth'

D

No error

Q282

Q282 In "SELECT Name, AGE(BirthDate) AS Age FROM Customers;",
what needs correction?

A

AGE

B

BirthDate

C

AS Age

D

No error

Q283

Q283 What needs to be corrected in "SELECT ABS(-123) FROM Dual;"?

A

Replace 'ABS' with 'MOD'

B

Change '-123' to '123'

C

Remove 'FROM Dual'

D

No error

Q284

Q284 Identify the error in "SELECT Name, CEILING(Salary) FROM Employees WHERE Salary > 0;"

A

Change 'CEILING' to 'FLOOR'

B

Replace 'Salary > 0' with 'Salary >= 0'

C

Add 'AS RoundedSalary' for clarity

D

No error

Q285

Q285 Correct the syntax error in "SELECT Name, ROUND(Salary, -2) FROM Employees;"

A

Change 'ROUND' to 'TRUNC'

B

Replace '-2' with '2'

C

Add 'AS RoundedSalary' for clarity

D

No error

Q286

Q286 What is incorrect in "SELECT MAX(Salary) - MIN(Salary) AS SalaryRange FROM Employees;"?

A

Replace 'MAX' with 'SUM'

B

Change '-' to '+'

C

Remove 'AS SalaryRange'

D

No error

Q287

Q287 In "SELECT Name, LOG(Salary, 10) AS LogSalary FROM Employees WHERE Salary > 0;", what needs correction?

A

Change 'LOG' to 'EXP'

B

Replace '10' with '2'

C

Remove 'WHERE Salary > 0'

D

No error

Q288

Q288 What needs to be corrected in "SELECT CONCAT(FirstName, ' ', LastName) FROM Employees;"?

A

Change 'CONCAT' to 'CONCATENATE'

B

Replace ',' with '+'

C

Add 'AS FullName' for clarity

D

No error

Q289

Q289 Identify the error in "SELECT SUBSTRING(Name, 1, 3) AS ShortName FROM Products;"

A

Change 'SUBSTRING' to 'LEFT'

B

Replace '1, 3' with '3'

C

Remove 'AS ShortName'

D

No error

Q290

Q290 Correct the syntax error in "SELECT Name, CHARINDEX('a', Name) FROM Employees WHERE Name IS NOT NULL;"

A

Change 'CHARINDEX' to 'INDEXOF'

B

Replace 'a' with '%a%'

C

Remove 'WHERE Name IS NOT NULL'

D

No error

Q291

Q291 What is incorrect in "SELECT UPPER(Name) FROM Employees;"?

A

Replace 'UPPER' with 'LOWER'

B

Change 'Name' to 'EmployeeName'

C

Add 'AS UppercaseName' for clarity

D

No error

Q292

Q292 In "SELECT Name, LTRIM(RTRIM(Name)) AS TrimmedName FROM Customers;", what needs correction?

A

Change 'LTRIM(RTRIM(Name))' to 'TRIM(Name)'

B

Remove 'AS TrimmedName'

C

Replace 'Name' with 'CustomerName'

D

No error

Q293

Q293 What is a correlated subquery in SQL?

A

A subquery that can be executed independently of the outer query

B

A subquery that uses values from the outer query

C

A subquery that returns multiple columns

D

A subquery used in the FROM clause

Q294

Q294 Identify the error in "SELECT Name FROM Employees WHERE Salary > (SELECT AVG(Salary) FROM Employees);"

A

Replace 'WHERE' with 'AND'

B

Change '>' to '<'

C

Add 'GROUP BY' after subquery

D

No error

Q295

Q295 What needs to be corrected in "SELECT Name FROM Employees WHERE EXISTS (SELECT * FROM Departments WHERE Employees.DepartmentID = Departments.DepartmentID);"?

A

Change 'WHERE EXISTS' to 'IF EXISTS'

B

Replace '*' with 'DepartmentID'

C

Add 'GROUP BY Name' at the end

D

No error

Q296

Q296 Correct the syntax error in "SELECT Name, (SELECT MAX(Salary) FROM Employees) AS MaxSalary FROM Employees WHERE DepartmentID = (SELECT DepartmentID FROM Departments WHERE Name = 'HR');"

A

Change the inner 'SELECT MAX(Salary)' to 'SUM(Salary)'

B

Remove 'AS MaxSalary'

C

Replace the second 'SELECT' with 'IN'

D

No error

Q297

Q297 What is a view in SQL?

A

A physical table stored in the database

B

A temporary table created during a session

C

A virtual table based on the result-set of an SQL statement

D

A duplicate copy of another table

Q298

Q298 What is a materialized view in SQL?

A

A view that is automatically updated when the underlying tables change

B

A view that is created for temporary use only

C

A view that is stored physically on the disk

D

A view that can be indexed

Q299

Q299 Identify the error in "CREATE VIEW ActiveEmployees AS SELECT * FROM Employees WHERE Status = 'Active';"

A

Change 'CREATE VIEW' to 'CREATE TABLE'

B

Replace '*' with specific column names

C

Remove 'WHERE Status = 'Active''

D

No error

Q300

Q300 What needs to be corrected in "CREATE OR REPLACE VIEW DepartmentSummary AS SELECT DepartmentID, COUNT(*) FROM Employees GROUP BY DepartmentID;"?

A

Change 'CREATE OR REPLACE VIEW' to 'CREATE VIEW'

B

Replace 'COUNT(*)' with 'COUNT(EmployeeID)'

C

Add 'ORDER BY DepartmentID' at the end

D

No error

ad vertical
ad