码迷,mamicode.com
首页 > 数据库 > 详细

mysql 创建表和外键

时间:2017-04-16 10:58:18      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:image   建表   images   _id   img   blog   log   arch   upd   

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> ccreate 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)
  >) ENGINE = InnoDB default charset=utf8;

技术分享

 

mysql 创建表和外键

标签:image   建表   images   _id   img   blog   log   arch   upd   

原文地址:http://www.cnblogs.com/yangxuming/p/6718094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!