Weird MySQL syntax error with simple CREATE TABLE statement

China☆狼群 提交于 2019-12-13 21:13:28

问题


Error:

#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 '‘00000000000’ membership_status ENUM(‘gold’,‘silver’,‘bronze’,' at line 5

SQL:

CREATE TABLE members(
member_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(60)NOT NULL,
birthday DATE NOT NULL,
phone CHAR(10)NOT NULL DEFAULT ‘00000000000’,
membership_status ENUM(‘gold’,‘silver’,‘bronze’,‘nam’)NOT NULL DEFAULT ‘nam’,
PRIMARY KEY(member_id)    
)   

回答1:


I'd guess it was the funky single quotes you're trying to use. Try this with standard ' single quotes

CREATE TABLE members(
    member_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    name VARCHAR(60)NOT NULL,
    birthday DATE NOT NULL,
    phone CHAR(10)NOT NULL DEFAULT '00000000000',
    membership_status ENUM('gold','silver','bronze','nam') NOT NULL DEFAULT 'nam',
    PRIMARY KEY(member_id)
)



回答2:


try this

CREATE TABLE members(
  member_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(60)NOT NULL,
  birthday DATE NOT NULL,
  phone CHAR(10)NOT NULL DEFAULT '0000000000',
  membership_status ENUM('gold','silver','bronze','nam')NOT NULL DEFAULT 'nam',
  PRIMARY KEY(member_id)    
)

I changed the single quotes to plain ' and your default value for phone was also 1 to many 0s




回答3:


The single quotes used are not recognized by the database server. Replace those fancy quotes with the regular one ' and you will be okay.
Note that you'll encounter problems in other programs as long as you use that kind of quotes as they are not the proper quotes to be used.

Hope this helps.



来源:https://stackoverflow.com/questions/17728542/weird-mysql-syntax-error-with-simple-create-table-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!