Free Source Code and Tutorials

Custom Search

SQL Drop Table


MySql Drop Table declaration allow deleting tables from the MySql Database. After dropping tables, it removed all of its data permanently by using the SQL command. Since every table is separated by a comma, it is also possible to delete all tables by using “Drop Table” condition.


The first method :

DROP TABLE [table_name];

By writing this code in the command line, it will delete the table from the Database. In order to connect MySql server, you have to install some package from the command prompt.

For Linux; Install MySql on Ubuntu to the droplet, “sudo apt-get install mysql-server “ command should be written. After this step, “mysql –u root -p” command has to be typed into to terminal which provides to access the MySql shell.

For Windows; “C:\>cd \ MYSQL\Bin” and “C:\>cd \ MYSQL\Bin>mysql –u root –p admin” commands need to be written to the terminal.


In addition to this, the syntax of all statement for drop table is,

DROP [ Temporary ] TABLE  [If Exists ]

1_table_name, 2_table_name,

[Restrain | Progressive];

By writing this statement, it will drop the only Temporary tables from the Database and this statement allows dropping the tables without giving any error. It is also possible to give the name of tables specifically. Restraint and progressive have meant that it consists of porting the tables to the different databases.

For instance,

DROP TABLE 1_Table, 2_Table, .. ;

This query will check the tables, and if there exists any table like in the statement, it will be deleted with all data. However, if there is no table of the same name, there will be an error message on MySql.

DROP TABLE IF EXISTS 1_Table, 2_Table, ..;

This query is going to explore the tables separately and if it is caught the same table like in the query, it is going to be deleted from the Database. Otherwise, if it does not exist any message will be displayed.


  1. <html>
  2. <head>
  3. <title>Creating MySQL Tables in a given database</title>
  4. </head>
  5. <body>
  6. <?php
  7. $dbhost = 'localhost;
  8. $dbusername = 'root';
  9. $dbpassword = 'rootpassword';
  10. $conn = mysql_connect($dbhost, $dbusername, $dbpassword);
  11. if(! $con )
  12. {
  13.  die('Could not connect: ' . mysql_error());
  14. }
  15. echo 'Connected successfully<br />';
  16. $sql = "DROP TABLE tutorials_Person";
  17. mysql_select_db( 'Database TUTORIALS' );
  18. $result = mysql_query( $sql, $con );
  19. if(! $result )
  20. {
  21.  die('Could not delete table: ' . mysql_error());
  22. }
  23. echo "Table has been  deleted successfully\n";
  24. mysql_close($con);
  25. ?>
  26. </body>
  27. </html>
Facebook Comments
(Visited 2 times, 1 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: