SQL Drop Index, Table, and Database
- Previous Page SQL Create Index
- Next Page SQL Alter
By using the DROP statement, it is easy to delete indexes, tables, and databases.
SQL DROP INDEX Statement
We can use the DROP INDEX command to delete an index from the table.
Syntax for Microsoft SQLJet (and Microsoft Access):
DROP INDEX index_name ON table_name
Syntax for MS SQL Server:
DROP INDEX table_name.index_name
Syntax for IBM DB2 and Oracle:
DROP INDEX index_name
Syntax for MySQL:
ALTER TABLE table_name DROP INDEX index_name
SQL DROP TABLE Statement
The DROP TABLE statement is used to delete a table (the structure, attributes, and indexes of the table will also be deleted):
DROP TABLE Table Name
SQL DROP DATABASE Statement
The DROP DATABASE statement is used to delete a database:
DROP DATABASE Database Name
SQL TRUNCATE TABLE Statement
If we only need to remove the data in the table but not delete the table itself, then how should we do it?
Please use the TRUNCATE TABLE command (which only deletes data in the table):
TRUNCATE TABLE Table Name
- Previous Page SQL Create Index
- Next Page SQL Alter