This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Drop DB”.
1. Which of the following command is used to delete a database in SQL?
a) DELETE
b) DROP
c) ERASE
d) TRUNCATE
View Answer
Explanation: The DROP command is used to delete a database in SQL. The same command can be used to delete a table within the database. The DELETE command is used to delete the specific information present inside the table. The TRUNCATE command is used to delete complete data from the table. Be careful while using the DROP command for deleting the database as it will affect all the tables present inside the database.
2. Which of the following statement is used to delete a database in SQL?
a) DROP DATABASE
b) DROP database_name
c) DROP DATABASE database_name
d) DROP DATABASE (database_name)
View Answer
Explanation: The syntax which is used to delete a database in SQL is –
DROP DATABASE database_name
In this statement DROP and DATABASE are keywords that remain the same for every statement using the DROP command, while database_name is the specific name of the database which has to be dropped and varies from statement to statement. The same syntax is used when using DROP for deleting a table.
3. Can a database be dropped regardless of its state?
a) True
b) False
View Answer
Explanation: A database can be dropped regardless of its state i.e. offline, read-only, suspect, etc. To view the current state of a database we can use the sys.databases catalog view.
4. After dropping a database snapshot in SQL, it can be re-created by restoring a backup.
a) True
b) False
View Answer
Explanation: In SQL, a dropped database can only be re-created by restoring a backup of it. But the database snapshots cannot be backed up and, therefore, cannot be restored.
5. Which of the following statement can be used to drop multiple databases at once?
a) DROP DATABASE database_name1 and database_name2
b) DELETE DATABASE database_name1, database_name2
c) DROP database_name1, database_name2
d) DROP DATABASE database_name1, database_name2
View Answer
Explanation: By using the statement – DROP DATABASE database_name1, database_name2, we can drop each of the listed databases. In the statement, database names are just separated by a comma (,).
6. In SQL, a database that is currently in use cannot be dropped.
a) True
b) False
View Answer
Explanation: You cannot drop a database currently being used i.e. open for reading or writing by any user. One way to remove users from the database is to use the ALTER DATABASE command to set the database to SINGLE_USER.
7. Which of the following statement is used to conditionally drop a database that already exists?
a) DROP DATABASE IF NOT EXISTS database_name
b) DROP DATABASE IF EXISTS database_name
c) DROP DATABASE EXISTS database_name
d) DROP DATABASE NOT EXISTS database_name
View Answer
Explanation: The IF EXISTS command is used with the DROP command to conditionally drop a database only if it already exists in the SQL Server. If we try to drop a database that is not present, SQL will give us an error. To prevent an error from occurring we can use the IF EXISTS option.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, 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]