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 ]
[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.
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.
$dbhost = 'localhost;
$dbusername = 'root';
$dbpassword = 'rootpassword';
$conn = mysql_connect($dbhost, $dbusername, $dbpassword);
if(! $con )
die('Could not connect: ' . mysql_error());
echo 'Connected successfully
$sql = "DROP TABLE tutorials_Person";
mysql_select_db( 'Database TUTORIALS' );
$result = mysql_query( $sql, $con );
if(! $result )
die('Could not delete table: ' . mysql_error());
echo "Table has been deleted successfully\n";