DROP in MySQL

Drop Database 

 
Dropping or deleting a MySQL database is easy. The drop statement command is used when we have to no longer use one of the SQL databases on the server. It will remove permanently and very easy to drop an existing MySQL table. But we need to be very careful while deleting any existing table because when data lost will not be recovered after deleting a table.
 
Here we have to drop a database on the server.
 
Syntax
Drop Database Database name
 
For Example
  1. mysql> drop database world; 
img 1.gif
 

The DROP INDEX Statement

 
The DROP INDEX the statement is used to delete an index in a table.
 
Syntax
 
ALTER TABLE table_name DROP INDEX index_name
 
For Example
  1. mysql> Alter table HeadOfState ADD PRIMARY KEY (ID),ADD INDEX (LastName,FirstName);  
  2.   
  3. mysql> ALTER TABLE HeadOfState DROP INDEX LastName; 
img alter index.gif
 

The DROP TABLE Statement

 
DROP TABLE removes one or more tables. We must have the DROP advantages for each table. All table data and the table definition are removed. DROP TABLE permanently removes the table definition, all of its partitions, and all of the data which was stored in those partitions.
 
The DROP TABLE statement is used to delete a table.
 
Syntax
DROP TABLE table_name
 
Example
  1. mysql> DROP table Employee;
drop table.gif
 

Altering and Dropping Tables

 
Example
  1. Drop table Stock;  
  2.   
  3. CREATE TABLE Stock  
  4. (  
  5. ID SMALLINT  
  6. );  
  7.   
  8. mysql> Describe Stock;  
  9.   
  10. mysql> ALTER TABLE Stock  
  11.       -> ADD COLUMN Quantity SMALLINT UNSIGNED NOT NULL,  
  12.      -> MODIFY ID SMALLINT UNSIGNED NOT NULL,  
  13.      -> ADD PRIMARY KEY (ID);  
  14.   
  15. mysql> Describe Stock; 
img alter and drop table.gif
 
  1. mysql>ALTER TABLE Stock;  
  2. mysql>DROP COLUMN Quantity,  
  3.      ->DROP PRIMARY KEY;  
  4.   
  5. mysql> Describe Stock; 
img alter and drop table2.gif
 
Note
 
All table data and the table definition are removed, so be careful with this statement!
 
Resources 
 
Here are some useful related resources: