如何根据以下要求设计我的数据库?
我正在考虑使用字段parent_app_id和child_app_id创建一个新表“Application relation”,它们都引用了application_id?我能这样做吗?
非常感谢任何帮助或想法
答案 0 :(得分:0)
正如@SloanThrashe所述,他的评论很清楚
CREATE TABLE Application(
application_id int NOT NULL AUTO_INCREMENT,
application_name varchar(50) NOT NULL,
fk_application_id int NULL,
PRIMARY KEY (ID)
);
Insert into Application(application_id, application_name, fk_application_id)
values (1, 'HR', null), (2, 'Timesheet',1), (3,'Leave Request', 1);
选择声明
Select p.application_id PID
, p.application_name Parent_App
, c.application_name Child_App
From Application p
Inner join Application c on p.application_id = c.fk_application_id
SQL结果
PID Parent_App Child_App
1 HR Timesheet
1 HR Leave Request