skip to Main Content
CREATE TABLE `users`(    
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,    
`name` VARCHAR(75) NOT NULL,    `password` VARCHAR(255) NOT NULL,    
`email` VARCHAR(100) NOT NULL,    
PRIMARY KEY `id`    
UNIQUE KEY `email` (`email`)
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1;

That’s my code for the query I’m trying to run in the phpmyadmin sql query runner to create a table for my users. When I try running the code I get the following error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNIQUE KEY `email` (`email`)
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE...' at line 7

Can someone please help me fix the syntax.

2

Answers


  1. Chosen as BEST ANSWER

    The above answer works but I did: ''' CREATE TABLE users(
    id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(75) NOT NULL,
    password VARCHAR(255) NOT NULL,
    email VARCHAR(100) NOT NULL UNIQUE KEY,
    )ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1; ''' and it works as well, you can choose whichever. Thanks for the response eshirvana!


  2. here is the right syntax:

    missing comma after pk , missing parentheses defining PK, and wrong syntax for unique key

    CREATE TABLE `users`(    
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,    
    `name` VARCHAR(75) NOT NULL,    
    `password` VARCHAR(255) NOT NULL,    
    `email` VARCHAR(100) NOT NULL,    
    PRIMARY KEY (`id`) ,   
    UNIQUE KEY  (`email`)
    )ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search