SQL DROP TABLE Statement

SQL DROP TABLE Statement

SQL DROP TABLE Statement

The SQL DROP TABLE statement is used to remove a table and all its associated objects such as indexes, triggers, constraints, etc. from a database. The syntax for the DROP TABLE statement is as follows:

				
					DROP TABLE table_name; 
				
			

Where table_name is the name of the table that you want to drop.

For example, let’s say we have a table named “employees” that we want to remove from our database. We can use the following DROP TABLE statement:

				
					DROP TABLE employees; 
				
			

This statement removes the “employees” table and all its associated objects from the database. It is important to note that when you use the DROP TABLE statement, all data in the table will be permanently deleted and cannot be recovered. Therefore, it is recommended to be very careful when using this statement and ensure that you have taken a backup of the table before executing this statement.

If you want to remove only specific columns from a table, you can use the ALTER TABLE statement to do so. For example, the following statement removes the “phone” column from the “employees” table:

				
					ALTER TABLE employees
DROP COLUMN phone; 

				
			

This statement removes the “phone” column from the “employees” table without affecting the rest of the table’s structure or data.

Join To Get Our Newsletter
Spread the love