你的表类型???
看手册,foreign key 好像只有innodb表类型才支持吧。

解决方案 »

  1.   

    mysql会自动处理InnoDB类型的,创建county表的语句就是InnoDB类型的。
    还请问一下,谁有最新的mysql的中文手册?
      

  2.   

    mysql会自动处理InnoDB类型的,创建county表的语句就是InnoDB类型的。
    ----------------------------------------------------------------
    什么意思啊?
      

  3.   

    我创建county表的语句也没有指定类型,但它会自动生成InnoDB类型。
    如何要指定InnoDB,如何写?请问你有mysql的中文手册吗?
      

  4.   

    会自动生成InnoDB类型
    --------------------
    你在配置文件中设置的么?create table county (
    countynumber integer not null auto_increment,
    countyname varchar(32),
    state varchar(32),
    primary key(countynumber)
    )type=innodb;
    ------------
    加上这个我只有英文手册。
      

  5.   

    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语句应该没错啊!
      

  6.   

    哦,我没有用到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;我这里试验过通过了。
      

  7.   

    谢谢!用修正后的SQL语句执行就没问题,非常感谢!知道哪里有mysql的论坛吗?
      

  8.   

    foreign key(countynumber) references county <---这个地方,括号里面应该是 index 的名字,而不是字段名!
    -----------------
    这一句不是很明白,你说的index的名字是指哪个表的索引名字,字段名又是哪个表的字段名?
      

  9.   

    我说乱了,毕竟不是写书的料啊,呵呵。
    还是给你一个手册上的例子,看了就会明白的。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 可以去看看