mysql drop statements

the tables,databases, and indexes, view can be removed with the drop statement.

mysql drop table statement

the MYSQL drop table statement removes a table and its data permanently from the database.

you can also remove multiple tables using a single drop table statement, each table is separated by a comma(,).

drop table syntax:

       drop      [temporary]     table    [if exists]     table_name1     [, table_name2] ....

the temporary flag allows you to drops only temporary tables.

example :

        drop    table      if exists    users, company ;

drop database statement

the drop database statement is used to delete a database.

syntax :

        drop     database     [if exists]      database_name

if exists is used to prevent an error from occurring if the database does not exist.

if the default database is dropped, the default database is unset(the database() function returns null).

drop index statement

the drop index statement is used to remove an index in a table.

     drop index     index_name   on    table_name ;


     alter     table    table_name    drop    index    index_name

drop view statement

mysql drop view command is used to drop a view.

    drop   view      [if exists]      view_name1, view_name2 ....

the if exists clause prevents an error from occurring for views that don't exist.

mysql truncate   table syntax

if we only want to delete the data inside the table, and not the table itself?

then, use the truncate table statement:

    truncate  table   table_name