欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-06 07:59:28
Database Design(数据库设计)(视频下载) (全部书籍) 马克-to-win: (一对多:one-to-many) 1) teacher and student. (teacher表:两列id(主键),name。pupil表: 三列:id(主键),name,tid(外键)) 举例: T ......

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