| |

VerySource

 Forgot password?
 Register
Search
Author: freeboy99

A database design problem, one-to-many relationship, how to design a table?

[Copy link]

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-27 18:45:01
| Show all posts
create table dept (
code int not null,
dep_code int null,
name char (50) not null,
constraint PK_DEPT primary key (code)
)
go

alter table dept
add constraint FK_DEPT_RELATIONS_DEPT foreign key (dep_code)
references dept (code)
go
------------------
code is the primary key of the department table, and dept_code is a special foreign key, which is a reference to its own primary key (code), which means that dept has a one-to-many relationship with itself.
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-21 11:30:02
| Show all posts
One table is enough (upper department number, own department number, name)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list