Back to Blog
Drop table if exists mysql6/23/2023 Mysql> create table orders2(order_date date, sale int) mysql> create table orders1(order_date date, sale int) Let’s say you have tables orders1, orders2, order3 in your database. For example, the following command WILL NOT WORK. If you have multiple database tables and you want to delete tables matching a particular pattern such as “order” then you cannot directly use MySQL DROP TABLE statement for it. If you have multiple tables table1, table2, table3 in same database, then here’s the MySQL DROP TABLE statement to delete them mysql> DROP TABLE table1, table2, table3 If you try to delete a non-existing table, then you will get a warning: mysql> drop table orders ĮRROR 1051 (42S02): Unknown table 'sample.orders'īonus Read : How to Get First Record in Each Group in MySQL Here’s the MySQL DROP TABLE statement to delete this table. mysql> create table orders(order_date date, sale int) Please note, in order to be able to delete a MySQL table, you must have DROP TABLE privileges.īonus Read : How to get record from today in MySQL IF EXISTS keyword will drop a table only if it exists. TEMPORARY keyword will delete only temporary tables and prevent non-temporary tables’ deletion. ĭROP TABLE statement can be used for removing one or more database tables. Here’s the syntax of DROP TABLE statement: DROP TABLE table_name. We will use the MySQL DROP TABLE statement to remove existing tables in a database. Here are the steps to drop table in MySQL. You can easily do this using MySQL DROP TABLE command. Sometimes you may need to delete table from database in MySQL.
0 Comments
Read More
Leave a Reply. |