Languages

MySQL - how to create table only if not exists?

0 points
Asked by:
Brett4
285

How can I create a table only if it doesn't already exist in MySQL?

1 answer
0 points
Answered by:
Brett4
285

I found a solution:

We can use the following syntax so we won't get errors while trying to create a table that already exists:

CREATE TABLE IF NOT EXISTS `table_name` (
    `column1` DATA_TYPE,
    `column2` DATA_TYPE,
    `column3` DATA_TYPE,
    ...
);

Check the article below to see some practical examples:

 

0 comments Add comment
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