
- MariaDB Tutorial
- MariaDB - Home
- MariaDB - Introduction
- MariaDB - Installation
- MariaDB - Administration
- MariaDB - PHP Syntax
- MariaDB - Connection
- MariaDB - Create Database
- MariaDB - Drop Database
- MariaDB - Select Database
- MariaDB - Data Types
- MariaDB - Create Tables
- MariaDB - Drop Tables
- MariaDB - Insert Query
- MariaDB - Select Query
- MariaDB - Where Clause
- MariaDB - Update Query
- MariaDB - Delete Query
- MariaDB - Like Clause
- MariaDB - Order By Clause
- MariaDB - Join
- MariaDB - Null Values
- MariaDB - Regular Expression
- MariaDB - Transactions
- MariaDB - Alter Command
- Indexes & Statistics Tables
- MariaDB - Temporary Tables
- MariaDB - Table Cloning
- MariaDB - Sequences
- MariaDB - Managing Duplicates
- MariaDB - SQL Injection Protection
- MariaDB - Backup Methods
- MariaDB - Backup Loading Methods
- MariaDB - Useful Functions
- MariaDB Useful Resources
- MariaDB - Quick Guide
- MariaDB - Useful Resources
- MariaDB - Discussion
MariaDB - Drop Tables
In this chapter, we will learn to delete tables.
Table deletion is very easy, but remember all deleted tables are irrecoverable. The general syntax for table deletion is as follows −
DROP TABLE table_name ;
Two options exist for performing a table drop: use the command prompt or a PHP script.
The Command Prompt
At the command prompt, simply use the DROP TABLE SQL command −
root@host# mysql -u root -p Enter password:******* mysql> use PRODUCTS; Database changed mysql> DROP TABLE products_tbl mysql> SELECT * from products_tbl ERROR 1146 (42S02): Table 'products_tbl' doesn't exist
PHP Drop Table Script
PHP provides mysql_query() for dropping tables. Simply pass its second argument the appropriate SQL command −
<html> <head> <title>Create a MariaDB Table</title> </head> <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 products_tbl"; mysql_select_db( 'PRODUCTS' ); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not delete table: ' . mysql_error()); } echo "Table deleted successfully\n"; mysql_close($conn); ?> </body> </html>
On successful table deletion, you will see the following output −
mysql> Table deleted successfully
Advertisements