Saturday, February 7, 2015

SQL DROP TABLE


SQL DROP TABLE


A SQL DROP TABLE statement is used to delete a table definition and all data from a table.
This is very important to know that once a table is deleted all the information available in the table is lost forever, so we have to be very careful when using this command.
Let's see the syntax to drop the table from the database.
  1. DROP TABLE "table_name";  
Let us take an example:
First we verify STUDENTS table and then we would delete it from the database.
SQL> DESC STUDENTS;
FIELDTYPENULLKEYDEFAULTEXTRA
IDInt(11)NOPRI
NAMEVarchar(20)NO
AGEInt(11)NO
ADDRESSVarchar(25)YESNULL
4 rows in set (0.00 sec)
This shows that STUDENTS table is available in the database, so we can drop it as follows:
SQL>DROP TABLE STUDENTS;
Query OK, 0 rows affected (0.01 sec)

SQL DROP TABLE Example in MySQL

Let's see the command to drop a table from the MySQL database.
  1. DROP TABLE hr_admin_emp;  

SQL DROP TABLE Example in Oracle

Let's see the command to drop a table from Oracle database.
  1. DROP TABLE marketing_emp;  

SQL DROP TABLE Example in Microsoft SQLServer

Let's see the command to drop a table from SQLServer database. It is same as MySQL.
  1. DROP TABLE product;  

No comments:

Post a Comment