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

数据库表中一对多关系怎么设计?

时间:2018-12-06 20:33:25      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:sig   bsp   values   html   http   OLE   creat   save   www.   

Database Design(数据库设计)(视频下载) (全部书籍)


马克-to-win:

(一对多:one-to-many)

1) teacher and student.

(teacher表:两列id(主键),name。
pupil表: 三列:id(主键),name,tid(外键))

 

举例: Teacher "qixy" has two students: liyaohua,fuwenlong. Teacher "huanglaosh" has two students: mashuai,jiaxiaohu.

create table pupil(id int not null,name char(10),tid int);

create table teacher(id int not null,name char(10));

INSERT INTO pupil (id,name,tid) VALUES(1,‘liyaohua‘,1);
INSERT INTO pupil (id,name,tid) VALUES(2,‘fuwenlong‘,1);
INSERT INTO pupil (id,name,tid) VALUES(3,‘mashuai‘,2);
INSERT INTO pupil (id,name,tid) VALUES(4,‘jiaxiaohu‘,2);

详情请看:http://www.mark-to-win.com/index.html?content=Mydb/DBUrl.html&chapter=Mydb/DBIntroduction_web.html#DesignOneMany

数据库表中一对多关系怎么设计?

标签:sig   bsp   values   html   http   OLE   creat   save   www.   

原文地址:https://www.cnblogs.com/mark-to-win/p/10078110.html

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