zhwz 发表于 2018-10-4 11:07:56

关于mysql外键

  首先要先明确mysql外检的作用,其实很简单,就是建立主表和从表的强制约束。
  看个例子:
  创建主表:
  

create table>id int(10) unsigned not null primary key auto_increment,  c_name varchar(30) not null default ''
  ) engine = innodb charset = utf8;
  

  创建从表:
  

create table stu (  id int(11) unsigned not null primary key auto_increment,
  name varchar(36) not null default '',
  c_id int(10) unsigned not null default 1,
  --创建外检语法

  foreign key(c_id) references>  )engine=innodb
  

  


  //foreign key(c_id) references>  1.c_id外键字段
  2.class主表




页: [1]
查看完整版本: 关于mysql外键