Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL "CREATE TABLE IF NOT EXISTS" -> Error 1050

Using the command:

CREATE TABLE IF NOT EXISTS `test`.`t1` (     `col` VARCHAR(16) NOT NULL ) ENGINE=MEMORY; 

Running this twice in the MySQL Query Browser results in:

Table 't1' already exists Error 1050

I would have thought that creating the table "IF NOT EXISTS" would not throw errors. Am I missing something or is this a bug? I am running version 5.1. Thanks.

like image 410
user199559 Avatar asked Oct 30 '09 16:10

user199559


People also ask

What is if not exists in MySQL?

The clause “if not exists” is used for the creation of tables and is very useful for avoiding the error “table already exists”, as it will not create a table if, in the database, any table is already available by the name of the new table.


2 Answers

Works fine for me in 5.0.27

I just get a warning (not an error) that the table exists;

like image 190
Eli Avatar answered Sep 19 '22 05:09

Eli


As already stated, it's a warning not an error, but (if like me) you want things to run without warnings, you can disable that warning, then re-enable it again when you're done.

SET sql_notes = 0;      -- Temporarily disable the "Table already exists" warning CREATE TABLE IF NOT EXISTS ... SET sql_notes = 1;      -- And then re-enable the warning again 
like image 25
gdt Avatar answered Sep 20 '22 05:09

gdt