user3188527
user3188527

Reputation: 31

SQL syntax error when creating table if it doesn't already exist

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXIST users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(255' at line 1

CREATE TABLE IF NOT EXIST `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(255) NOT NULL,
 `first_name` varchar(255) NOT NULL,
 `last_name` varchar(255) NOT NULL,
 `email` varchar(255) NOT NULL,
 `password` varchar(32) NOT NULL,
 `sign_up_date` date NOT NULL,
 `activated` enum('0','1') NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Upvotes: 1

Views: 2038

Answers (2)

Vickel
Vickel

Reputation: 8007

You have a syntax error in your sql:

 EXIST

should be

 EXISTS

Upvotes: 3

LorDex
LorDex

Reputation: 2636

EXISTS!

CREATE TABLE IF NOT EXISTS users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(255) NOT NULL, first_name varchar(255) NOT NULL, last_name varchar(255) NOT NULL, email varchar(255) NOT NULL, password varchar(32) NOT NULL, sign_up_date date NOT NULL, activated enum('0','1') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Upvotes: 3

Related Questions