我創建表與phpMyAdmin的語法:SQL外鍵
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS info;
CREATE TABLE users (
user_id int unsigned NOT NULL auto_increment,
email varchar(100) NOT NULL default '',
pwd varchar(32) NOT NULL default '',
isAdmin int(1) unsigned NOT NULL,
PRIMARY KEY (user_id)
) TYPE=INNODB;
CREATE TABLE info (
info_id int unsigned NOT NULL auto_increment,
first_name varchar(100) NOT NULL default '',
last_name varchar(100) NOT NULL default '',
address varchar(300) NOT NULL default '',
zipcode varchar(100) NOT NULL default '',
personal_phone varchar(100) NOT NULL default '',
mobilephone varchar(100) NOT NULL default '',
faxe varchar(100) NOT NULL default '',
email2 varchar(100) NOT NULL default '',
country varchar(100) NOT NULL default '',
sex varchar(1) NOT NULL default '',
birth varchar(1) NOT NULL default '',
email varchar(100) NOT NULL default '',
PRIMARY KEY (info_id),
FOREIGN KEY (email) REFERENCES users(email) ON UPDATE CASCADE ON DELETE CASCADE
) TYPE=INNODB;
但顯示了錯誤:
"#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 'TYPE=INNODB' at line 11 "
如果我刪除TYPE = INNODB在創建表的末尾,它會顯示錯誤:
"#1005 - Can't create table 'curriculo.info' (errno: 150) ".
如果我沒有指定他默認使用的引擎,但錯誤「#1005 - 無法創建表'curriculo.info'(errno:150)」 – 2012-04-11 23:25:29
可能因爲您沒有'UNIQUE KEY(email)在'users'表中。 – 2012-04-11 23:29:33
是的,就是這樣!謝謝 – 2012-04-11 23:35:36