程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

外鍵測試

編輯:關於MYSQL數據庫

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,
primary key (par_id)
) type = innodb;


create table child
(
par_id int not null,
child_id int not null,
primary 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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved