简体   繁体   中英

my sql error on creating and adding columns to table

I have the following SQL command:

ALTER TABLE `personal_information` ADD `applicant_name` VARCHAR(50) NOT NULL AFTER `ID`, ADD `mothers_name` VARCHAR(50) NOT NULL AFTER `applicant_name`, ADD `date_of_birth` DATE NOT NULL AFTER `mothers_name`, ADD `Place_of_birth` VARCHAR(200) NOT NULL AFTER `date_of_birth`, ADD `marital_status` ENUM(0) NOT NULL AFTER `Place_of_birth`, ADD `sex` ENUM(0) NOT NULL AFTER `marital_status`, ADD `religion` ENUM(0) NOT NULL AFTER `sex`, ADD `profession_ar` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `religion`, ADD `profession` VARCHAR(50) NOT NULL AFTER ` profession_ar`;

This is a new table. It only have ID(PRIMARY KEY) column. I am fully new to backend. So I Don't know much of anything about sql command. I got this from php my admin preview SQL btn. This creates an error. The error is:

ALTER TABLE `personal_information` ADD `applicant_name` VARCHAR(50) NOT NULL AFTER `ID`, ADD `mothers_name` VARCHAR(50) NOT NULL AFTER `applicant_name`, ADD `date_of_birth` DATE NOT NULL AFTER `mothers_name`, ADD `Place_of_birth` VARCHAR(200) NOT NULL AFTER `date_of_birth`, ADD `marital_status` ENUM(0) NOT NULL AFTER `Place_of_birth`, ADD `sex` ENUM(0) NOT NULL AFTER `marital_status`, ADD `religion` ENUM(0) NOT NULL AFTER `sex`, ADD `profession_ar` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `religion`, ADD `profession` VARCHAR(50) NOT NULL AFTER ` profession_ar`

MySQL said: Documentation

#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 '0) NOT NULL AFTER Place_of_birth , ADD sex ENUM(0) NOT NULL AFTER `marital_st' at line 1

I am using wamp and my sql version is 5.7.14. what can I do?

Edit:

None of the answer worked for me. Because, My phpmyadmin version was 4.6.4 Which don't support latest mysql Enum syntax. But My mysql server version is 5.7.14. So The old Enum syntax Don't Supported By mysql 5.7.14(may be supported, I am not sure, but together the MySQL 5.7.14 and phpmyadmin 4.6.4 was creating some issue). So I updated my phpmyadmin to version 4.6.5.2 and everything is working perfect.

Thanks guys for giving me answers. I will give upper votes once i get 15 reputations.

Your query should be like this:

ALTER TABLE `personal_information` ADD `applicant_name` VARCHAR(50) NOT NULL AFTER `ID`, ADD `mothers_name` VARCHAR(50) NOT NULL AFTER `applicant_name`, ADD `date_of_birth` DATE NOT NULL AFTER `mothers_name`, ADD `Place_of_birth` VARCHAR(200) NOT NULL AFTER `date_of_birth`, ADD `marital_status` ENUM('0') NOT NULL AFTER `Place_of_birth`, ADD `sex` ENUM('0') NOT NULL AFTER `marital_status`, ADD `religion` ENUM('0') NOT NULL AFTER `sex`, ADD `profession_ar` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `religion`, ADD `profession` VARCHAR(50) NOT NULL AFTER `profession_ar`;

You have to pass values in single quote to declare ENUM

edit: there is a gap on last profession_ar for which another error is occurring.

You should state the options of ENUM such as:

... ADD marital_status ENUM('single','married') NOT NULL AFTER Place_of_birth , ...

It's very simple, You just run the below query on the mysql editor. But don't forget to select the database. If you have any further query regarding this you can feel free knock me. Please notice your mistake. Thanks 在此处输入图片说明

ALTER TABLE personal_information
ADD COLUMN `applicant_name` VARCHAR(50) NOT NULL AFTER `id`,
ADD COLUMN `mothers_name` VARCHAR(50) NOT NULL AFTER `applicant_name`,
ADD COLUMN `date_of_birth` DATE NOT NULL AFTER `mothers_name`,
ADD COLUMN `Place_of_birth` VARCHAR(200) NOT NULL AFTER `date_of_birth`,
ADD COLUMN `sex` enum('1','2') NOT NULL COMMENT '1=M,2=F'  AFTER `Place_of_birth`,
ADD COLUMN `religion` ENUM('0','2') NOT NULL AFTER `sex`,
ADD COLUMN `profession_ar` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `religion`,
ADD COLUMN `profession` VARCHAR(50) NOT NULL AFTER `profession_ar`; 

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