MYSQL创建表+ Alter表语法不正确?

时间:2009-10-06 11:32:01

标签: sql mysql foreign-keys create-table

我正在尝试在Navicat中创建一个表,然后立即添加一个外键关系。然而,语法似乎不正确......这甚至可能吗?

    CREATE TABLE `Bld` (
      `id` int(10) NOT NULL
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ALTER TABLE `Bld` (
        CONSTRAINT `fk_Bld_Bld_Ref` FOREIGN KEY (`id`) REFERENCES `Bld_Ref` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    );

1 个答案:

答案 0 :(得分:4)

你错过了一个逗号:

CREATE TABLE `Bld` (
  `id` int(10) NOT NULL, -- <- there
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;