DROP a Single Table
Let’s create a new table named Student.
CREATE TABLE Student (
StdtId INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Dob DATE
);
Now, to delete the table Student, we will write the following statement.
DROP TABLE Student;
Explanation: This statement will delete the Student table from the database. It will delete all the records stored in the Student table.
SQL Server DROP TABLE
In SQL Server, the DROP TABLE statement is used to remove or delete permanently from the database. In SQL Server after performing the DROP Operation we cannot revoke the table or database again, because it is an irreversible action. The Drop Operation is different from the DELETE Command, In the DELETE command we can revoke the database or table after performing the DELETE Operation. Generally, we use the DROP TABLE command to delete or remove those tables that are useless.
Syntax:
DROP TABLE [IF EXISTS] table_name;
Explanation:
- DROP TABLE: The keyword used to delete a table from the database.
- IF EXISTS: This optional clause prevents an error from occurring if the table does not exist and If the table exists then it is dropped otherwise, nothing will happen.
- table_name: It is a table name that we want to drop from our database.
If we want to delete multiple tables at the same time then the below syntax would be follow.
DROP TABLE IF EXISTS table_name1, table_name2, table_name3;
Contact Us