原来mysql不支持外键,要用InnoDB才可以..
时间:2006-08-28 来源:小兵张嘎-kevin
原来一直用postgresql,最近接触到了mysql(5.0.20),它默认是MyISAM引擎,竟然不支持外键,后来才知道要用InnoDB引擎才能支持..
create database test;
use test;
CREATE TABLE userinfo (
userid character(8) primary key,
temp character(8)
)Type=INNODB CHARACTER SET utf8;
CREATE TABLE commenttest(
userid character(8),
comment character varying(200),
foreign key(userid) references userinfo(userid) on delete cascade)
Type= INNODB CHARACTER SET utf8;
insert into userinfo values("06000017","aaaa");
insert into userinfo values("06000020","bbbb");
insert into commenttest values("06000017","cccccc");
insert into commenttest values("06000020","ddddd");
create database test;
use test;
CREATE TABLE userinfo (
userid character(8) primary key,
temp character(8)
)Type=INNODB CHARACTER SET utf8;
CREATE TABLE commenttest(
userid character(8),
comment character varying(200),
foreign key(userid) references userinfo(userid) on delete cascade)
Type= INNODB CHARACTER SET utf8;
insert into userinfo values("06000017","aaaa");
insert into userinfo values("06000020","bbbb");
insert into commenttest values("06000017","cccccc");
insert into commenttest values("06000020","ddddd");
相关阅读 更多 +