Skip to main content

SQL DROP Statement

SQL DROP Statement

The SQL DROP statement is used to delete database objects such as tables, indexes, views, and stored procedures.


1. Dropping Tables

To delete an existing table from a database, you can use the DROP TABLE statement followed by the table name.

Example:

// Example of dropping a table named "employees"
DROP TABLE employees;

This example deletes the table named "employees" from the database.


2. Dropping Indexes

To remove an index from a table, you can use the DROP INDEX statement followed by the index name.

Example:

// Example of dropping an index named "idx_name" from the "employees" table
DROP INDEX idx_name ON employees;

This example deletes the index named "idx_name" from the "employees" table.


3. Dropping Views

To delete a view from the database, you can use the DROP VIEW statement followed by the view name.

Example:

// Example of dropping a view named "employee_view"
DROP VIEW employee_view;

This example deletes the view named "employee_view" from the database.


4. Conclusion

The DROP statement in SQL is used to remove existing database objects such as tables, indexes, and views. It is important to use the DROP statement carefully, as it permanently deletes the specified objects from the database.

Comments