2013-05-13 43 views
-1

顯然,我在下面的SQL語句語法錯誤:修正了我的MySQL錯誤#1064

create database project_line; 

use project_line; 

drop table if exists project; 
create table project 
(
    p_id int primary key, 
    p_nm varchar(255) not null, 
    p_line varchar(255) not null 
) 
ENGINE = INNODB; 

drop table if exists meta; 
create table meta 
(
    m_id primary key, 
    p_id not null, 
    meta_nm varchar(255) not null, 
    foreign key (p_id) references project (p_id) 
) 
ENGINE = INNODB; 

你能指出哪裏?

回答

0

你忘了m_idp_id

create table meta 
(
    m_id primary key,   <------here 
    p_id not null,    <------here 
    meta_nm varchar(255) not null, 
    foreign key (p_id) references project (p_id) 
) 

的數據類型應該是int

如果您使用像這樣的設計工具,例如MySQL Workbench,您會立即注意到這些錯誤,因爲它們會被突出顯示。

0

指定第二個表中的數據類型。試試這個SQL。

create table project 
(
    p_id int primary key, 
    p_nm varchar(255) not null, 
    p_line varchar(255) not null 
) 
ENGINE = INNODB; 


create table meta 
(
    m_id int primary key, 
    p_id int not null, 
    meta_nm varchar(255) not null, 
    foreign key (p_id) references project (p_id) 
) 
ENGINE = INNODB; 
+0

謝謝你!我應該可以睡一會兒:/ – 2013-05-13 10:47:16

+0

@ f1zz0_13:你應該將帖子標記爲答案,無論哪個人幫助你。 – ankurtr 2013-05-13 10:48:52

0

您缺少字段「m_id」和「p_id」的數據類型。這就是你錯誤即將到來的地方。試試這個:

create database project_line;

use project_line;

drop table if exists projects; 創建表項目 ( P_ID INT主鍵, p_nm VARCHAR(255)不爲空, p_line VARCHAR(255)不爲空 ) ENGINE = INNODB;

drop table if exists meta; 創建表的元 ( M_ID INT主鍵, 的p_id詮釋不爲空, meta_nm VARCHAR(255)NOT NULL, 外鍵(P_ID)引用項目(P_ID) ) ENGINE = INNODB;