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

SQL - Drop or Delete Table: Syntax

The SQL DROP TABLE statement is used to permanently delete a table and all of its contents from the database. The syntax is DROP TABLE table_name. As an example, a CUSTOMERS table is verified to exist using the DESC command and is then dropped using DROP TABLE. When DESC is run again, an error message indicates the table no longer exists.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

SQL - Drop or Delete Table: Syntax

The SQL DROP TABLE statement is used to permanently delete a table and all of its contents from the database. The syntax is DROP TABLE table_name. As an example, a CUSTOMERS table is verified to exist using the DESC command and is then dropped using DROP TABLE. When DESC is run again, an error message indicates the table no longer exists.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL - DROP OR DELETE TABLE

http://www.tuto rialspo int.co m/sql/sql-dro p-table .htm


Co pyrig ht tuto rials po int.co m

T he SQL DRO P T ABLE statement is used to remove a table definition and all data, indexes, trig g ers, constraints, and permission specifications for that table. NO T E: You have to be careful while using this command because once a table is deleted then all the information available in the table would also be lost forever.

Syntax:
Basic syntax of DROP T ABLE statement is as follows:
DROP TABLE table_name;

Example:
Let us first verify CUST OMERS table and then we would delete it from the database:
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)

T his means CUST OMERS table is available in the database, so let us drop it as follows:
SQL> DROP TABLE CUSTOMERS; Query OK, 0 rows affected (0.01 sec)

Now, if you would try DESC command, then you would g et error as follows:
SQL> DESC CUSTOMERS; ERROR 1146 (42S02): Table 'TEST.CUSTOMERS' doesn't exist

Here, T EST is database name which we are using for our examples.

You might also like