MySQL Delete Data Sheet
Deleting a data table in MySQL is very easy to do, but you should be careful when you delete a table, because all the data disappears when you execute the delete command.
Grammar
The following is a general syntax for deleting MySQL data tables:
;
To delete a data table in a command prompt window
Delete the data table in the Mysql> Command Prompt window The SQL statement is drop table :
Instance
The following example deletes the data table tutorials_tbl:
[Email protected] # mysql-u root-pEnter password:* ******mysql>use tutorials; Database changedmysql> DROP TABLE tutorials_tblQuery OK,0(0.8 SEC)mysql>
Delete a data table using a PHP script
PHP uses the mysql_query function to delete MySQL data tables.
The function has two parameters, returns TRUE on successful execution, or FALSE.
h3> syntax
BOOL mysql_query( sql,);
Parameters |
Description |
Sql |
Necessary. Specifies the SQL query to send. Note: The query string should not end with a semicolon. |
Connection |
Optional. Specifies the SQL connection identifier. If not specified, the previous open connection is used. |
Instance
The following example uses a PHP script to delete a data table tutorials_tbl:
<title>Creating MySQL Tables</title><body><?Php$dbhost= ' localhost:3036 ';$dbuser= ' Root ';$dbpass= ' Rootpassword ';$conn=Mysql_connect($dbhost,$dbuser,$dbpass);If(!$conn){ Die(' Could not connect: ' .Mysql_error());}Echo' Connected successfully<br/> ';$sql= "DROP TABLE tutorials_tbl";mysql_select_db( ' Tutorials ' );$retval=Mysql_query($sql, $conn ); if (! $retval ) { die ( ' Could not delete table: '
MySQL Delete data table