SQL Server Questions and Answers – Basic SQL – 3

This set of SQL Server Inteview Questions and Answers for freshers focuses on “Basic SQL – 3”.

1. Which of the following command makes the updates performed by the transaction permanent in the database?
a) ROLLBACK
b) COMMIT
c) TRUNCATE
d) DELETE
View Answer

Answer: b
Explanation: Commit command is used to permanently save any transaction into the database.

2. Which TCL command undo all the updates performed by the SQL in the transaction?
a) ROLLBACK
b) COMMIT
c) TRUNCATE
d) DELETE
View Answer

Answer: b
Explanation: Rollback is used for undoing the work done in the current transaction. This command also releases the locks if any hold by the current transaction.

3. SQL query to find all the cities whose humidity is 95.
a) SELECT city WHERE humidity = 95
b) SELECT city FROM weather WHERE humidity = 95
c) SELECT humidity = 89 FROM weather
d) SELECT city FROM weather
View Answer

Answer: b
Explanation: The SQL WHERE clause is used to filter the results and apply conditions in a SELECT, INSERT, UPDATE, or DELETE statement.
advertisement
advertisement

4. SQL query to find the temperature in increasing order of all cities.
a) SELECT city FROM weather ORDER BY temperature
b) SELECT city, temperature FROM weather
c) SELECT city, temperature FROM weather ORDER BY temperature
d) SELECT city, temperature FROM weather ORDER BY city
View Answer

Answer: d
Explanation: The ORDER BY keyword sorts the records in ascending order by default.

5. What is the meaning of LIKE ‘%0%0%’?
a) Feature begins with two 0’s
b) Feature ends with two 0’s
c) Feature has more than two 0’s
d) Feature has two 0’s in it, at any position
View Answer

Answer: d
Explanation: The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

6. Find the names of these cities with temperature and condition whose condition is neither sunny nor cloudy.
a) SELECT city, temperature, condition FROM weather WHERE condition NOT IN (‘sunny’, ‘cloudy’)
b) SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN (‘sunny’, ‘cloudy’)
c) SELECT city, temperature, condition FROM weather WHERE condition IN (‘sunny’, ‘cloudy’)
d) SELECT city, temperature, condition FROM weather WHERE condition BETWEEN (‘sunny’, ‘cloudy’);
View Answer

Answer: a
Explanation: The IN operator allows you to specify multiple values in a WHERE clause.

7. Find the name of those cities with temperature and condition whose condition is either sunny or cloudy but temperature must be greater than 70.
a) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ OR temperature > 70
b) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ OR temperature > 70
c) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ AND temperature > 70
d) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ AND temperature > 70
View Answer

Answer: c
Explanation: The AND operator displays a record if both the first condition AND the second condition are true. The OR operator displays a record if either the first condition OR the second condition is true.
advertisement

8. Find all the tuples having a temperature greater than ‘Paris’.
a) SELECT * FROM weather WHERE temperature > (SELECT temperature FROM weather WHERE city = ‘Paris’
b) SELECT * FROM weather WHERE temperature > (SELECT * FROM weather WHERE city = ‘Paris’)
c) SELECT * FROM weather WHERE temperature > (SELECT city FROM weather WHERE city = ‘Paris’)
d) SELECT * FROM weather WHERE temperature > ‘Paris’ temperature
View Answer

Answer: a
Explanation: Subquery—also referred to as an inner query or inner select—is a SELECT statement embedded within a data manipulation language (DML) statement or nested within another subquery.

9. Find all the cities with temperature, condition and humidity whose humidity is in the range of 63 to 79.
a) SELECT * FROM weather WHERE humidity IN (63 to 79)
b) SELECT * FROM weather WHERE humidity NOT IN (63 AND 79)
c) SELECT * FROM weather WHERE humidity BETWEEN 63 AND 79
d) SELECT * FROM weather WHERE humidity NOT BETWEEN 63 AND 79
View Answer

Answer: c
Explanation: The BETWEEN operator is used to select values within a range.
advertisement

10. The command to remove rows from a table ‘CUSTOMER’ is __________________
a) DROP FROM CUSTOMER
b) UPDATE FROM CUSTOMER
c) REMOVE FROM CUSTOMER
d) DELETE FROM CUSTOMER WHERE
View Answer

Answer: d
Explanation: The SQL DELETE Query is used to delete the existing records from a table. You can use WHERE clause with the DELETE query to delete selected rows.

Sanfoundry Global Education & Learning Series – SQL Server.

To practice all areas of SQL Server for freshers attending interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.