SQL Server Questions and Answers – Basic SQL – 2

This set of SQL Server Multiple Choice Questions and Answers for freshers focuses on “Basic SQL – 2”.

1. What does DML stand for?
a) Different Mode Level
b) Data Model Language
c) Data Mode Lane
d) Data Manipulation language

Answer: d
Explanation: Data Manipulation Language is used to modify the records in the database.

2. With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”?
a) SELECT * FROM Persons WHERE FirstName=’a’
b) SELECT * FROM Persons WHERE FirstName LIKE ‘a%’
c) SELECT * FROM Persons WHERE FirstName LIKE ‘%a’
d) SELECT * FROM Persons WHERE FirstName=’%a%’

Answer: c
Explanation: The SQL LIKE clause is used to compare a value to similar values using wildcard operators.

3. With SQL, how can you return all the records from a table named “Persons” sorted descending by “FirstName”?
a) SELECT * FROM Persons SORT BY ‘FirstName’ DESC
b) SELECT * FROM Persons ORDER FirstName DESC
c) SELECT * FROM Persons SORT ‘FirstName’ DESC
d) SELECT * FROM Persons ORDER BY FirstName DESC

Answer: d
Explanation: The SQL SELECT statement queries data from tables in the database.

4. With SQL, how can you return the number of not null records in the “Persons” table?
a) SELECT COUNT() FROM Persons
b) SELECT COLUMNS() FROM Persons
c) SELECT COLUMNS(*) FROM Persons
d) SELECT COUNT(*) FROM Persons

Answer: a
Explanation: COUNT(column_name) is used to count the number of rows of a table where column name is a column that does not allow NULL values.

5. What does the ALTER TABLE clause do?
a) The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints
b) The SQL ALTER TABLE clause is used to insert data into database table
c) THE SQL ALTER TABLE deletes data from database table
d) The SQL ALTER TABLE clause is used to delete a database table

Answer: a
Explanation: The ALTER TABLE statement is used to add, delete, or modify columns.

6. The UPDATE SQL clause can _____________
a) update only one row at a time
b) update more than one row at a time
c) delete more than one row at a time
d) delete only one row at a time

Answer: b
Explanation: The SQL UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows otherwise all the rows would be affected.

7. The UNION SQL clause can be used with _____________
a) SELECT clause only
b) DELETE and UPDATE clauses
c) UPDATE clause only
d) All of the mentioned

Answer: a
Explanation: The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements. It removes duplicate rows between the various SELECT statements.

8. Which SQL statement is used to return only different values?
a) SELECT DIFFERENT
b) SELECT UNIQUE
c) SELECT DISTINCT
d) SELECT ALL

Answer: c
Explanation: The SELECT DISTINCT statement is used to return only distinct (different) values.

9. Which SQL keyword is used to sort the result-set?
a) ORDER BY
b) SORT
c) ORDER
d) SORT BY

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

10. How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
a) UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
b) MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
c) MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
d) UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’

Answer: d
Explanation: In its simplest form, the syntax for the UPDATE statement when updating one table is:UPDATE table SET column1 = expression1,column2 = expression2,… WHERE conditions.

Leave a Comment