MySql Drop Table

MySql Delete Tables

MySql DROP TABLE commmand is used to delete the mysql tables.

drop table syntax,

DROP TABLE <table-name1>, <table-name2>,.....

Let us consider mysql example table and try the drop table command,

mysql> use mysqldemo;
Database changed

mysql> select * from tblemployee1;
+--------+----------+---------+--------+
| emp_id | emp_name | dept_id | salary |
+--------+----------+---------+--------+
|      1 | emp1     |      10 |  10000 |
|      2 | emp2     |      11 |  20000 |
|      3 | emp3     |      10 |  15000 |
|      4 | emp4     |      11 |  12000 |
+--------+----------+---------+--------+
4 rows in set (0.00 sec)

mysql> drop table tblemployee1;
Query OK, 0 rows affected (0.55 sec)

mysql> select * from tblemployee1;
ERROR 1146 (42S02): Table 'mysqldemo.tblemployee1' doesn't exist
mysql>

mysql 'tblemployee1' table which contains 4 rows, drop table command is used to delete this table from currently used mysql databases.

drop multiple mysql tables

Let us see the example mysql drop commmand is used to delete the multiple tables in mysql database.


mysql> select * from tblemployee1;
ERROR 1146 (42S02): Table 'mysqldemo.tblemployee1' doesn't exist
mysql>  create table tblemployee1(
         emp_id INT NOT NULL AUTO_INCREMENT,
          emp_name VARCHAR(100) NOT NULL,
        dept_id INT,
           salary INT,
          PRIMARY KEY ( emp_id )
         );
Query OK, 0 rows affected (0.48 sec)

mysql> insert into tblemployee1 (emp_id, emp_name, dept_id, salary) select * from tblemployee;
Query OK, 4 rows affected (0.37 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from tblemployee1;
+--------+----------+---------+--------+
| emp_id | emp_name | dept_id | salary |
+--------+----------+---------+--------+
|      1 | emp1     |      10 |  10000 |
|      2 | emp2     |      11 |  20000 |
|      3 | emp3     |      10 |  15000 |
|      4 | emp4     |      11 |  12000 |
+--------+----------+---------+--------+
4 rows in set (0.00 sec)

mysql>  create table tblemployee2(
           emp_id INT NOT NULL AUTO_INCREMENT,
          emp_name VARCHAR(100) NOT NULL,
           dept_id INT,
          salary INT,
           PRIMARY KEY ( emp_id )
         );
Query OK, 0 rows affected (0.48 sec)

mysql> insert into tblemployee2 (emp_id, emp_name, dept_id, salary) select * from tblemployee;
Query OK, 4 rows affected (0.37 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from tblemployee2;
+--------+----------+---------+--------+
| emp_id | emp_name | dept_id | salary |
+--------+----------+---------+--------+
|      1 | emp1     |      10 |  10000 |
|      2 | emp2     |      11 |  20000 |
|      3 | emp3     |      10 |  15000 |
|      4 | emp4     |      11 |  12000 |
+--------+----------+---------+--------+
4 rows in set (0.00 sec)

mysql> DROP TABLE tblemployee1, tblemployee2;
Query OK, 0 rows affected (0.24 sec)

mysql> select * from tblemployee1;
ERROR 1146 (42S02): Table 'mysqldemo.tblemployee1' doesn't exist
mysql> select * from tblemployee2;
ERROR 1146 (42S02): Table 'mysqldemo.tblemployee2' doesn't exist
mysql>



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^