简体   繁体   中英

SQL syntax error in Mysql version 5.6 when creating a table

I have created a table in my sql file and I always get the error,

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 ' ' at line 29.

I couldn't find my error. Here is my database table:

CREATE TABLE IF NOT EXISTS `student` (
        `stud_ID` INT(11) NOT NULL,
        `org_ID` INT(11) NOT NULL,
        `faculty_ID`    INT(11) NOT NULL,
        `fName` VARCHAR(30) NOT NULL,
        `lName` VARCHAR(30) NOT NULL,
        `mName` VARCHAR(30) NOT NULL,
        `DOB`date DEFAULT NULL,
        `gender` ENUM('male', 'female') NOT NULL,
        `religion` char(20) NOT NULL,
        `home_add` VARCHAR(100) NOT NULL,
        `telnum` INT(10) NOT NULL,
        `mobile` INT(20) NOT NULL,
        `email_address`     VARCHAR(50) NOT NULL,
        `username` VARCHAR(20) NOT NULL,
        `password` VARCHAR(20) NOT NULL,
        `con_password` VARCHAR(20) NOT NULL,
        `lastSchoolAttend` VARCHAR(50) NOT NULL,

        `lastYear` INT  NOT NULL,
        `lastSchoolADD` VARCHAR(100) NOT NULL,
        `stud_status` ENUM('okay', 'proby', 'suspended', 'kicked-out') NOT NULL  )ENGINE=InnoDB AUTO_INCREMENT;

can someone answer me why I have this error and pinpoint what my error is? thank you!

Assuming that stud_id is the primary key and its auto increment

CREATE TABLE IF NOT EXISTS `student` (
        `stud_ID` INT(11)AUTO_INCREMENT PRIMARY KEY NOT NULL,
        `org_ID` INT(11) NOT NULL,
        `faculty_ID`    INT(11) NOT NULL,
        `fName` VARCHAR(30) NOT NULL,
        `lName` VARCHAR(30) NOT NULL,
        `mName` VARCHAR(30) NOT NULL,
        `DOB`date DEFAULT NULL,
        `gender` ENUM('male', 'female') NOT NULL,
        `religion` char(20) NOT NULL,
        `home_add` VARCHAR(100) NOT NULL,
        `telnum` INT(10) NOT NULL,
        `mobile` INT(20) NOT NULL,
        `email_address`     VARCHAR(50) NOT NULL,
        `username` VARCHAR(20) NOT NULL,
        `password` VARCHAR(20) NOT NULL,
        `con_password` VARCHAR(20) NOT NULL,
        `lastSchoolAttend` VARCHAR(50) NOT NULL,

        `lastYear` INT  NOT NULL,
        `lastSchoolADD` VARCHAR(100) NOT NULL,
        `stud_status` ENUM('okay', 'proby', 'suspended', 'kicked-out') NOT NULL  )ENGINE=InnoDB;

Else, if you want it without auto increment / primary key which is not so nice way, just remove AUTO_INCREMENT from last line of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM