Asyraf
Asyraf

Reputation: 657

ERROR 1064 (42000): You have an error in your SQL syntax; error in line 1

I try to make a simple table in MySQL with this command;

CREATE TABLE users (
            id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY,
            firstname VARCHAR(30) NOT NULL,
            lastname VARCHAR(30) NOT NULL,
            email VARCHAR(30) NOT NULL
);

Then, I get this error;

ERROR 1064 (42000): 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 ', firstname varchar(30) NOT NULL, lastname varchar(30) NOT NULL, email varchar(' at line 1

Can you guys help me? I'm still new with Mysql...

Upvotes: 0

Views: 3096

Answers (3)

Prathyusha
Prathyusha

Reputation: 45

You can try this way

CREATE TABLE users (
            id INT(6) UNSIGNED AUTO_INCREMENT,
            firstname VARCHAR(30) NOT NULL,
            lastname VARCHAR(30) NOT NULL,
            email VARCHAR(30) NOT NULL,
            PRIMARY KEY ( id )
);

Upvotes: 1

LFC
LFC

Reputation: 50

You have assigned Primary Key wrongly. Use code :-

CREATE TABLE users (
        id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        firstname VARCHAR(30) NOT NULL,
        lastname VARCHAR(30) NOT NULL,
        email VARCHAR(30) NOT NULL

);

Upvotes: 0

Marcelo Origoni
Marcelo Origoni

Reputation: 318

You forgot the KEY keyword

CREATE TABLE users (
            id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            firstname VARCHAR(30) NOT NULL,
            lastname VARCHAR(30) NOT NULL,
            email VARCHAR(30) NOT NULL
);

Upvotes: 1

Related Questions