如何在数据库中保存信息?我有一个字典表A和一个字典表B,并且要根据表A中某些列的值,我希望从表B中获取一些行。
我想知道哪种数据库结构对我而言是最好的(最好的-最专业,最有效的等)
我有一张表d_required_activity(一个字典):
CREATE TABLE d_required_activity (
id bigserial primary key,
activity text not null,
);
和d_violence_factor(字典):
CREATE TABLE d_violence_factor (
id bigserial primary key,
range numrange not null,
score text not null,
description text not null,
);
现在,根据 d_violence_factor.score ,我想从 d_required_activity 中获得一些活动,例如,当 d_violence_factor.score = 3 时>然后我必须从 d_required_activity 中获取3行。
我创建了第三个表: d_violence_factor_d_required_activity:
CREATE TABLE d_violence_factor_d_required_activity (
required_activity_id bigserial not null,
violence_factor_id bigserial not null,
PRIMARY KEY(required_activity_id, violence_factor_id)
);
insert into d_violence_factor_d_required_activity (required_activity_id, violence_factor_id)
values
(1, 1),
(2, 2),
(3, 3),
(4, 3),
(3, 4),
(4, 4),
(5, 4),
(3, 5),
(4, 5),
(5, 5);
这是一个好方法吗?我现在应该为d_violence_factor_d_required_activity添加实体,还是您会看到更好的方法?
我使用Spring Boot和JPA + Hibernate ...