Languages

MySQL - drop table if exists

4 points
Asked by:
Marcino
720

I have a question how do I drop table if exists in MySQL?
I know it is possible in other databases.
Also I know I can remove this table with sql:

DROP TABLE `users_table`;

But it doesn't protect me from error if this table was already removed
or it never existed.

1 answer
2 points
Answered by:
Marcino
720

Quickest way to do which will solve your problem:

DROP TABLE IF EXISTS `users_table`;

Explanation:

users_table - database table name you want to remove

if exists - will ensure you won't get any error if the table was never created

From MySQL documentation:

DROP TABLE IF EXISTS `table_name`;

 

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join