WEB开发网
开发学院数据库MySQL 外键测试 阅读

外键测试

 2007-11-11 15:14:20 来源:WEB开发网   
核心提示:DROP TABLE IF EXISTS child;DROP TABLE IF EXISTS parent;DROP TABLE IF EXISTS child;DROP TABLE IF EXISTS parent;# creat table startcreate table parent( par_id int

DROP TABLE IF EXISTS child;
DROP TABLE IF EXISTS parent;

DROP TABLE IF EXISTS child;
DROP TABLE IF EXISTS parent;

# creat table start
create table parent
(
 par_id int not null,
 Prima(最完善的虚拟主机管理系统)ry key (par_id)
) type = innodb;


create table child
(
 par_id int not null,
 child_id int not null,
 Prima(最完善的虚拟主机管理系统)ry key (par_id,child_id),
 foreign key (par_id) references parent (par_id) on delete cascade
) type = innodb;

# creat table end

# insert strat

insert into parent (par_id) values (1),(2),(3);
insert into child (par_id,child_id) values (1,1),(1,2);
insert into child (par_id,child_id) values (2,1),(2,2),(2,3);
insert into child (par_id,child_id) values (3,1);

# insert end

Tags:测试

编辑录入:coldstar [复制链接] [打 印]
赞助商链接