本帖最后由 DarrenFu1019 于 2010-06-09 23:29:13 编辑

解决方案 »

  1.   

    这个应该是印刷错误,或者写书的人把``括起符弄成''括起符了。,就是把`fk_city_country`弄成'fk_city_country'了。
    你copy下边的文本就OK了:
    create table city(city_id smallint unsigned not null 
    auto_increment,city varchar(50) not null,country_id smallint 
    unsigned not null,last_update timestamp not null default 
    current_timestamp on update current_timestamp,
    primary key(city_id),constraint `fk_city_country` foreign key(country_id) 
    references country(country_id) on delete restrict on update cascade) engine=innodb 
    default charset=utf8;
    或者不用指定constraint name,使用:
    create table city(city_id smallint unsigned not null 
    auto_increment,city varchar(50) not null,country_id smallint 
    unsigned not null,last_update timestamp not null default 
    current_timestamp on update current_timestamp,
    primary key(city_id),foreign key(country_id) 
    references country(country_id) on delete restrict on update cascade) engine=innodb 
    default charset=utf8;如:
    mysql> create table city(city_id smallint unsigned not null
        -> auto_increment,city varchar(50) not null,country_id smallint
        -> unsigned not null,last_update timestamp not null default
        -> current_timestamp on update current_timestamp,
        -> primary key(city_id),foreign key(country_id)
        -> references country(country_id) on delete restrict on update cascade) engine=innodb
        -> default charset=utf8;
    Query OK, 0 rows affected (0.02 sec)
      

  2.   

     'fk_city_country'-> `fk_city_country`