我正在尝试为一家软件开发公司创建一个数据库(作为一个空闲时间项目)
我已经为此苦苦挣扎了一段时间,是时候向你们寻求帮助了。
我有 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 的外观:ER 图
这是 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