用带有外键的sql语句创建mysql表出错 你的表类型???看手册,foreign key 好像只有innodb表类型才支持吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mysql会自动处理InnoDB类型的,创建county表的语句就是InnoDB类型的。还请问一下,谁有最新的mysql的中文手册? mysql会自动处理InnoDB类型的,创建county表的语句就是InnoDB类型的。----------------------------------------------------------------什么意思啊? 我创建county表的语句也没有指定类型,但它会自动生成InnoDB类型。如何要指定InnoDB,如何写?请问你有mysql的中文手册吗? 会自动生成InnoDB类型--------------------你在配置文件中设置的么?create table county (countynumber integer not null auto_increment,countyname varchar(32),state varchar(32),primary key(countynumber))type=innodb;------------加上这个我只有英文手册。 MySQL4.1.15安装后,配置文件中默认的数据库类型是InnoDB。如果有外键,就是加了type = InnoDB还是报一样的错,不知道你试过没有?create table voterregistration (ssn integer not null,firstname varchar(32) not null,lastname varchar(32) not null,countynumber integer not null,primary key(SSN),foreign key(countynumber) references county)type=InnoDB;SQL语句应该没错啊! 哦,我没有用到4.1.15,也没有默认配置为InnoDB,所以有点奇怪。仔细看了一下,你的SQL语句是错的。create table voterregistration ( ssn integer not null, firstname varchar(32) not null, lastname varchar(32) not null, countynumber integer not null, primary key(SSN), foreign key(countynumber) references county <---这个地方,括号里面应该是 index 的名字,而不是字段名!)type=InnoDB;用这个:create table voterregistration ( ssn integer not null primary key, firstname varchar(32) not null, lastname varchar(32) not null, countynumber integer not null, index (countynumber), foreign key(countynumber) references county(countynumber))type=InnoDB;我这里试验过通过了。 谢谢!用修正后的SQL语句执行就没问题,非常感谢!知道哪里有mysql的论坛吗? foreign key(countynumber) references county <---这个地方,括号里面应该是 index 的名字,而不是字段名!-----------------这一句不是很明白,你说的index的名字是指哪个表的索引名字,字段名又是哪个表的字段名? 我说乱了,毕竟不是写书的料啊,呵呵。还是给你一个手册上的例子,看了就会明白的。CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB;CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id), <----对外键字段进行索引 FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE) TYPE=INNODB;mysql 论坛我也不知道哪个好点,我一般都是看手册,然后google搜索。www.chinaunix.com 可以去看看 大家好,问一下删除外键的问题 想问一下最新发布的mysql 5.5.x有什么新特性好用吗? php 查询mysql时,表为空时出错 如何把在线数据库的所有操作都记录下来 这个删除语句怎么写.高手帮忙看下 mysql与正则表达式 问一个查询的问题(立刻给分) 怎样建表才高效? 请问是什么问题?(如图) 数据查询求教,请大侠帮忙,急 求一个mysql的sql计算语句 请大虾介绍比较好的导入工具
还请问一下,谁有最新的mysql的中文手册?
----------------------------------------------------------------
什么意思啊?
如何要指定InnoDB,如何写?请问你有mysql的中文手册吗?
--------------------
你在配置文件中设置的么?create table county (
countynumber integer not null auto_increment,
countyname varchar(32),
state varchar(32),
primary key(countynumber)
)type=innodb;
------------
加上这个我只有英文手册。
create table voterregistration (
ssn integer not null,
firstname varchar(32) not null,
lastname varchar(32) not null,
countynumber integer not null,
primary key(SSN),
foreign key(countynumber) references county)
type=InnoDB;
SQL语句应该没错啊!
仔细看了一下,你的SQL语句是错的。
create table voterregistration (
ssn integer not null,
firstname varchar(32) not null,
lastname varchar(32) not null,
countynumber integer not null,
primary key(SSN),
foreign key(countynumber) references county <---这个地方,括号里面应该是 index 的名字,而不是字段名!
)
type=InnoDB;用这个:
create table voterregistration (
ssn integer not null primary key,
firstname varchar(32) not null,
lastname varchar(32) not null,
countynumber integer not null,
index (countynumber),
foreign key(countynumber) references county(countynumber)
)
type=InnoDB;我这里试验过通过了。
-----------------
这一句不是很明白,你说的index的名字是指哪个表的索引名字,字段名又是哪个表的字段名?
还是给你一个手册上的例子,看了就会明白的。CREATE TABLE parent(id INT NOT NULL,
PRIMARY KEY (id)
) TYPE=INNODB;CREATE TABLE child(id INT,
parent_id INT,
INDEX par_ind (parent_id), <----对外键字段进行索引
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) TYPE=INNODB;mysql 论坛我也不知道哪个好点,我一般都是看手册,然后google搜索。
www.chinaunix.com 可以去看看