ER图中的关系

时间:2016-01-04 00:10:21

标签: sql entity-relationship er-diagrams er-diagram

我正在尝试为软件开发公司创建数据库(作为空闲时间项目)

我一直在努力解决这个问题,现在是时候向你们寻求帮助了。

我有3个实体,PROGRAMMER,PROGRAM和PLATFORM。程序员可以在许多平台上工作,程序可以在许多平台上工作,程序员可以在许多程序上工作。但对于特定程序,程序员只能使用一个平台。所以我创建了另一个名为WORKS的表,它具有以下属性:Programmer_ID,Program_ID和Platform_ID。前两个是主键,因此它符合上述规范。

现在,问题出现的地方是:程序员可以监督程序(这不是强制性的)。监督团队会面,数据库必须存储每个程序的team_ID和会议的DATE,也是Meeting_ID,但这是无关紧要的。

所以,我必须创建一个不允许在Programmer_ID - Program_ID对上重复的表,以便同一个人不会再次出现在同一个组中,同时它必须有一个Team_ID女巫将是相同的编号为Program_ID,它必须将Team_ID引用到MEETING表,以便我可以存储它。我怎么能这样做?

感谢您的时间。

PS:以下是我的急诊室看法:ER Diagram

这是MS SQL 2012中导出的DLL:

CREATE
  TABLE CUSTOMER
  (
    Customer_ID NUMERIC (5) NOT NULL ,
    Name        CHAR (30) NOT NULL ,
    PR_Guy      CHAR (30) NOT NULL ,
    Phone       CHAR (20) NOT NULL
  )
  ON "default"
GO
ALTER TABLE CUSTOMER ADD CONSTRAINT CUSTOMER_PK PRIMARY KEY CLUSTERED (
Customer_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE KNOWS
  (
    Programmer_ID NUMERIC (5) NOT NULL ,
    Prog_Lang_ID  NUMERIC (3) NOT NULL
  )
  ON "default"
GO
ALTER TABLE KNOWS ADD CONSTRAINT KNOWS_PK PRIMARY KEY CLUSTERED (Programmer_ID,
Prog_Lang_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE MEETING_DATE
  (
    Meeting_ID    NUMERIC (3) NOT NULL ,
                  DATE DATE ,
    Program_ID    NUMERIC (5) ,
    Programmer_ID NUMERIC (5)
  )
  ON "default"
GO
ALTER TABLE MEETING_DATE ADD CONSTRAINT MEETING_DATE_PK PRIMARY KEY CLUSTERED (
Meeting_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE PLATFORM
  (
    Platform_ID   NUMERIC (5) NOT NULL ,
    Name          CHAR (30) NOT NULL ,
    OS            CHAR (30) ,
    Latest_Update DATE NOT NULL ,
    Dev_Name      CHAR (30) NOT NULL
  )
  ON "default"
GO
ALTER TABLE PLATFORM ADD CONSTRAINT PLATFORM_PK PRIMARY KEY CLUSTERED (
Platform_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE PROGRAM
  (
    Program_ID  NUMERIC (5) NOT NULL ,
    Name        CHAR (30) NOT NULL ,
    Deadline    DATE NOT NULL ,
    Customer_ID NUMERIC (5) NOT NULL
  )
  ON "default"
GO
ALTER TABLE PROGRAM ADD CONSTRAINT PROGRAM_PK PRIMARY KEY CLUSTERED (Program_ID
)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE PROGRAMMER
  (
    Programmer_ID NUMERIC (5) NOT NULL ,
    First_Name    CHAR (30) NOT NULL ,
    Last_Name     CHAR (30) NOT NULL ,
    Money_Status  NUMERIC (1) NOT NULL
  )
  ON "default"
GO
ALTER TABLE PROGRAMMER ADD CONSTRAINT PROGRAMMER_PK PRIMARY KEY CLUSTERED (
Programmer_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE PROG_LANG
  (
    Prog_Lang_ID NUMERIC (3) NOT NULL ,
    Name         CHAR (30) NOT NULL
  )
  ON "default"
GO
ALTER TABLE PROG_LANG ADD CONSTRAINT PROG_LANG_PK PRIMARY KEY CLUSTERED (
Prog_Lang_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE SUPERVISE
  (
    Programmer_ID NUMERIC (5) NOT NULL ,
    Program_ID    NUMERIC (5) NOT NULL ,
    Group_ID      NUMERIC (5) NOT NULL
  )
  ON "default"
GO
ALTER TABLE SUPERVISE ADD CONSTRAINT SUPERVISE_PK PRIMARY KEY CLUSTERED (
Program_ID, Programmer_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

CREATE
  TABLE WORKS
  (
    Programmer_ID NUMERIC (5) NOT NULL ,
    Program_ID    NUMERIC (5) NOT NULL ,
    Platform_ID   NUMERIC (5) NOT NULL
  )
  ON "default"
GO
ALTER TABLE WORKS ADD CONSTRAINT WORKS_PK PRIMARY KEY CLUSTERED (Programmer_ID,
Program_ID)
WITH
  (
    ALLOW_PAGE_LOCKS = ON ,
    ALLOW_ROW_LOCKS  = ON
  )
  ON "default"
GO

ALTER TABLE KNOWS
ADD CONSTRAINT FK_ASS_2 FOREIGN KEY
(
Programmer_ID
)
REFERENCES PROGRAMMER
(
Programmer_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE KNOWS
ADD CONSTRAINT FK_ASS_3 FOREIGN KEY
(
Prog_Lang_ID
)
REFERENCES PROG_LANG
(
Prog_Lang_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE MEETING_DATE
ADD CONSTRAINT MEETING_DATE_SUPERVISE_FK FOREIGN KEY
(
Program_ID,
Programmer_ID
)
REFERENCES SUPERVISE
(
Program_ID ,
Programmer_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE PROGRAM
ADD CONSTRAINT PROGRAM_CUSTOMER_FK FOREIGN KEY
(
Customer_ID
)
REFERENCES CUSTOMER
(
Customer_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE SUPERVISE
ADD CONSTRAINT SUPERVISE_WORKS_FK FOREIGN KEY
(
Programmer_ID,
Program_ID
)
REFERENCES WORKS
(
Programmer_ID ,
Program_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE WORKS
ADD CONSTRAINT WORKS_PLATFORM_FK FOREIGN KEY
(
Platform_ID
)
REFERENCES PLATFORM
(
Platform_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE WORKS
ADD CONSTRAINT WORKS_PROGRAMMER_FK FOREIGN KEY
(
Programmer_ID
)
REFERENCES PROGRAMMER
(
Programmer_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

ALTER TABLE WORKS
ADD CONSTRAINT WORKS_PROGRAM_FK FOREIGN KEY
(
Program_ID
)
REFERENCES PROGRAM
(
Program_ID
)
ON
DELETE
  NO ACTION ON
UPDATE NO ACTION
GO

1 个答案:

答案 0 :(得分:0)

由于要显示图像,因此无法将其添加到评论中。

如果您的WORKS表有一个主键,其中包含全部3个,即PROGRAMMER_ID,PROGRAM_ID和PLATFORM_ID,则MEETING表可以是WORKS表的子表,我认为可以解决您的问题。

见下图

enter image description here