0% found this document useful (0 votes)
44 views

SQL - DROP or DELETE Table

The SQL DROP TABLE statement is used to remove a table definition and all its data from the database. It is important to be careful when using DROP TABLE as it permanently deletes the table and its contents. The basic syntax is DROP TABLE table_name. An example shows verifying the structure of the CUSTOMERS table, dropping it using DROP TABLE CUSTOMERS, and getting an error when trying to describe the table again since it no longer exists.

Uploaded by

Marlon Magtibay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

SQL - DROP or DELETE Table

The SQL DROP TABLE statement is used to remove a table definition and all its data from the database. It is important to be careful when using DROP TABLE as it permanently deletes the table and its contents. The basic syntax is DROP TABLE table_name. An example shows verifying the structure of the CUSTOMERS table, dropping it using DROP TABLE CUSTOMERS, and getting an error when trying to describe the table again since it no longer exists.

Uploaded by

Marlon Magtibay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL - DROP or DELETE Table

The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes,
triggers, constraints and permission specifications for that table.
NOTE − You should be very careful while using this command because once a table is deleted
then all the information available in that table will also be lost forever.

Syntax
The basic syntax of this DROP TABLE statement is as follows −
DROP TABLE table_name;
Example
Let us first verify the CUSTOMERS table and then we will delete it from the database as shown
below −
SQL> DESC CUSTOMERS;
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ID | int(11) | NO | PRI | | |
| NAME | varchar(20) | NO | | | |
| AGE | int(11) | NO | | | |
| ADDRESS | char(25) | YES | | NULL | |
| SALARY | decimal(18,2) | YES | | NULL | |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
This means that the CUSTOMERS table is available in the database, so let us now drop it as
shown below.
SQL> DROP TABLE CUSTOMERS;
Query OK, 0 rows affected (0.01 sec)
Now, if you would try the DESC command, then you will get the following error −
SQL> DESC CUSTOMERS;
ERROR 1146 (42S02): Table 'TEST.CUSTOMERS' doesn't exist
Here, TEST is the database name which we are using for our examples.

You might also like