外键约束求助 本帖最后由 DarrenFu1019 于 2010-06-09 23:29:13 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个应该是印刷错误,或者写书的人把``括起符弄成''括起符了。,就是把`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) 'fk_city_country'-> `fk_city_country` 高分求助MySql Update语句 查询字段内一部分内容? 数据同步问题(急) Linux英文版中mysql储存显示中文!请教!! 对于300万数据量的数据库优化问题 如何获取某个表的条目数? MyODBC Not Found??不解 mysql 1064错误 〓〓〓〓 关于MySQLDB 〓〓〓〓 mysql查询结果拆分行 关于创建存储过程的问题,求助 SQL高手求助?????十三豆呢?
你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)