mysql 创建表和外键
Posted 西瓜的夏天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 创建表和外键相关的知识,希望对你有一定的参考价值。
mysql> create table country(
> country_id smallint unsigned not null auto_increment,
>country varchar(50) not null,
>last_update timestamp not null default current_timestamp on update current_timestamp,
>primary key (country_id)
>)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),
>key idx_fk_country_id (country_id),
>foreign key (country_id) references country (country_id)
>ON UPDATE CASCADE ON DELETE RESTRICT
>) ENGINE = InnoDB default charset=utf8;
以上是关于mysql 创建表和外键的主要内容,如果未能解决你的问题,请参考以下文章