| |

VerySource

 Forgot password?
 Register
Search
View: 1561|Reply: 11

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

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 19:40:01
| Show all posts |Read mode
There are first-level departments and sub-departments in the enterprise

For example, there is a planning center and a research and development center, which belong to the first-level department.
The planning center includes the design department, the planning department, and the editorial department.
The R & D center includes the Delphi R & D department and the Java R & D department.

What to do when designing the department information sheet?
I currently design it like this
A total of two tables
One table is the first-level department information table
department1:
  First Department Number
  First-level department name

department2:
  First Department Number
  Secondary department number
  Secondary department name

Because some departments have no sub-secondary departments.

Do you think there is something wrong with the design above?
A first-level department can have multiple second-level departments or no second-level departments
A secondary department corresponds to only one primary department

In the actual situation of the enterprise, shouldn't there be two identical second-level department names under different first-level departments?

How to optimize my database design above? Or better suggestions ???
Thank you..
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-23 15:00:02
| Show all posts
A table should be fine.
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 Unknown

Post time: 2020-1-23 15:09:01
| Show all posts
For example:
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
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 18:45:02
| Show all posts
This kind of problem is done with the parent-child table relationship

One is the department code table

One is the job code table. This table should contain the department where the job is located.
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 19:00:01
| Show all posts
One is the department code table (dept_no, dept_name), and the primary key is dept_no

One is the position code table (position_no, position_name, dept_no), the primary key is position_no

The structure of these two tables is very important to the structure of the entire company
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-23 20:18:01
| Show all posts
Agree with the first floor
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-23 23:36:01
| Show all posts
In the actual situation of the enterprise, shouldn't there be two identical second-level department names under different first-level departments?

There will be two identical secondary departments, but only the same name, the number is different!
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-27 16:27:01
| Show all posts
create table #department
(
dep_no numeric primary key,
dep_name varchar (20),
father_dep_no numeric references #department (dep_no)
)

insert into #department values ​​(1, 'Plan Center', null)
insert into #department values ​​(2, 'R & D Center', null)
insert into #department values ​​(3, 'Design Department', 1)
insert into #department values ​​(4, 'Planning Department', 1)
insert into #department values ​​(5, 'Editor', 1)
insert into #department values ​​(6, 'delphi R & D', 2)
insert into #department values ​​(7, 'java R & D', 2)
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-27 17:00:01
| Show all posts
Not quite sure whatunkmassmeans. .

Can you write it in relational mode? ?
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-27 18:09:01
| Show all posts
Because I am not involved in employee positions here. .

Only the department involved
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