2017-04-30 76 views
-2

IM當我運行此查詢MySQL的語法錯誤在創建表查詢

CREATE TABLE `teacher` (
    'id' int(11) NOT NULL, 
    'name' varchar(45) NOT NULL, 
    'gender' ENUM('F','M') NOT NULL, 
    'department' varchar(32) NOT NULL, 
    PRIMARY KEY (`id`), 
    FOREIGN KEY ('department') REFERENCES  
    departments('name') 
); 

#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 
''id' int(11) NOT NULL, 'name' varchar(45) NOT NULL, 'gender' ENUM('F','M') N' 
at line 2 

這個錯誤顯示出來

+2

反引號和引號是不同的東西 – Strawberry

+0

如何笨我的 三江源配合<3 – mask477

回答

1

創建通過phpmyadmin在MySQL表試試這個:

CREATE TABLE teacher (
id int(11) NOT NULL, 
name varchar(45) NOT NULL, 
gender ENUM('F', 'M') NOT NULL, 
department varchar(32) NOT NULL, 
PRIMARY KEY (id), 
FOREIGN KEY (department) REFERENCES departments(name) 
); 
1

嘗試

CREATE TABLE teacher (
id int(11) NOT NULL, 
name varchar(45) NOT NULL, 
gender ENUM('F','M') NOT NULL, 
department varchar(32) NOT NULL, 
PRIMARY KEY (id), 
FOREIGN KEY (department) REFERENCES  
departments(name) 
); 

for mor ÈClick