0

I am trying to create a database for a software development company (as a free time project)

I've been struggling with this for quite a while now, it's time to ask you guys for help.

I have 3 entities, PROGRAMMER, PROGRAM and PLATFORM. A programmer can work on many platforms, a program can be worked on many platforms and a programmer can work on many programs. BUT for a specific program the programmer can only work with one platform. So I created another table called WORKS witch has the following attributes: Programmer_ID, Program_ID and Platform_ID. The first two are Primary Keys so that it meets the specifications above.

Now, is where the problem starts: Programmers can supervise a program (it's not mandatory). The supervising team meets and the database has to store a team_ID for every program and a DATE for the meeting, also a Meeting_ID but that's irrelevant.

So, I have to make a table that doesn't allow duplicates on the pair Programmer_ID - Program_ID so that the same person wont be on the same group a second time, also it has to have a Team_ID witch will be the same number as the Program_ID and it has to reference the Team_ID to the MEETING table so I can store it. How can I do such a thing?

Thank you for your time.

PS: Here is how my ER looks: ER Diagram

And this is the exported DLL in MS SQL 2012:

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
The Gramm
  • 118
  • 2
  • 12

1 Answers1

0

Could not put this in a comment since there is an image to be shown.

If your WORKS table has a primary key that has all 3 i.e. PROGRAMMER_ID, PROGRAM_ID and PLATFORM_ID then the MEETING table can be a child of the WORKS table and that I think may address your issue.

See below diagram

enter image description here

vmachan
  • 1,672
  • 1
  • 10
  • 10
  • The primary key for Works is Programmer_ID and Program_ID. Not Platform_ID. The point is to not be able to have the same programmer working on the same program on more than 1 platforms. What I want to end up with is a table that has Team_ID, Programmer_ID and Program_ID. Team_ID is not unique while the other two are. – The Gramm Jan 04 '16 at 00:36
  • Also the teams must be created even if there is not a meeting set up yet. – The Gramm Jan 04 '16 at 00:40
  • So in that case, you drop PLATFORM_ID from the PK for WORKS, and have another 1-N relation from PROGRAM to MEETING based on PROGRAM_ID which is called TEAM_ID in the MEETING table.. – vmachan Jan 04 '16 at 00:41
  • Someone does not understand, it's either me or you. Sadly I'm new to the world of SQL. Basically what I need is a table of tables. So the first entry will be all the programmers that make up the first team, the second all the programmers that make up the second and so on. Is there such a thing? – The Gramm Jan 04 '16 at 00:52
  • k.. will give it another shot here.. you need a TEAM table for every PROGRAM, there can only be one TEAM per PROGRAM, but many PROGRAMMERS on this TEAM.. with one PROGRAMMER as the supervisor, is that a fair assessment? – vmachan Jan 04 '16 at 00:55
  • Nope! :) Every PROGRAM has some programmers working on it. Everyone of them IF he wants he can be in the supervising team. So there are two teams one working and one both working and supervising. Get it? :P It's kinda strange! – The Gramm Jan 04 '16 at 00:58
  • Well since I just found out the solution I'll post it [here](http://prntscr.com/9lt9cu) (It's the ER diagram) everything works as it should. @vmachan you helped in a way so thanks! – The Gramm Jan 04 '16 at 01:48