Home > Software design >  #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv

Time:01-02

CREATE table sign_up(
    firstname varchar(150),
    lastname varchar(150),
    birthdate date,
    tel int(8),
    cin int(8) PRIMARY,
    email varchar(150) PRIMARY,
    motdepass varchar(10) PRIMARY);

MySQL said:

#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 ' email varchar(150) PRIMARY, motdepass varchar(10) PRIMARY)' at line 6

CodePudding user response:

Correct syntax for multi-column primary key in mysql is like this:

CREATE table sign_up(
    firstname varchar(150),
    lastname varchar(150),
    birthdate date,
    tel int(8),
    cin int(8),
    email varchar(150),
    motdepass varchar(10),
    PRIMARY KEY(cin, email, motdepass)
    )
    ;

On the other hand, if what you're looking for is to set cin as primary key, but want email and motdepass to be unique, then:

CREATE table sign_up(
    firstname varchar(150),
    lastname varchar(150),
    birthdate date,
    tel int(8),
    cin int(8) primary key,
    email varchar(150) unique,
    motdepass varchar(10) unique
    )
    ;

However, forcing motdepass (which is I guess where you store user passwords) to be unique may not be a great idea, since if a user with malicious intent tries to create an account in your application, and the app throws an error, then given that everything else is correct, the user will know that someone else already used the same password.

CodePudding user response:

CREATE TABLE IF NOT EXISTS `sign_up`(
    'firstname' varchar(150),
    'lastname' varchar(150),
    'birthdate' date,
    'tel' int(8),
    PRIMARY KEY 'cin' int(8) ,
    KEY 'email' varchar(150),
    KEY 'motdepass' varchar(10));

it cannot have more than one primary key. you can check same issue Can a Microsoft SQL table have more than one Primary Key?

  • Related