How to resolve MySQL ERROR 1050 (42S01): Table already exists

Here we will see why MySQL throw error ERROR 1050 (42S01): Table already exists.

You might have seen this error when you are trying to create a new table in MySQL.

ERROR 1050 (42S01)

MySQL throws ERROR 1050 (42S01) when the table already exists and we try to create a new table with the same name.

create table dept(id int, name varchar(20));
ERROR 1050 (42S01): Table 'dept' already exists

How to resolve ERROR 1050 (42S01): Table already exists

We can handle Error 1050 in MySQL by using if not exists clause, if we use if not exists clause while executing create table statement then MySQL will not throw any error.

Note: if we use the if not exists clause then it does mean that table will be created, it will not throw an error. 

Syntax:

Create Table if not exists dept(id int, name varchar(20));
Query OK, 0 rows affected, 1 warning (0.00 sec)

It will not throw ERROR 1050 (42S01) error.

Scroll to Top