Composite primary key and foreign key part of PK?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
abajaj11
Posts: 3
Joined: 2014-04-07 04:41

Composite primary key and foreign key part of PK?

Post by abajaj11 » 2014-04-07 04:49

I have database schemas, wherein I have several tables with a composite primary key (meaning 2 0r more columns together make up a single PK).
I also frequently have FKs in a table also be part of the PK of that table.
I just started using appgini today and on a simple schema, it said:
-A foreign key cannot also be a primary key, and
-A table cannot have > 1 PK..implying that I can only have a single column PK.

Is this a limitation of appgini? Only single column PK and a PK in a table cannot be an FK as well? In other words use only auto-generated IDs or something for each table?
thank you for any help you may be able to provide!
-abajaj11

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Composite primary key and foreign key part of PK?

Post by AhmedBR » 2014-04-07 11:37

AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

abajaj11
Posts: 3
Joined: 2014-04-07 04:41

Re: Composite primary key and foreign key part of PK?

Post by abajaj11 » 2014-04-07 11:51

Yes, I saw that already before i made my post...thanks for the link.
that solution does not solve my problem...
Here is an example schema:
Professors (f_id, f_name, f_address, f_specialty, highest_degree)
Courses (c_id, c_name, num_credits)
Sections (c_id, s_id, time_held, week_days_held, date_began, date_ended, cl_id)
c_id FOREIGN KEY REFERENCES Courses, cl_id FOREIGN KEY REFERENCES Classrooms

Students (st_id, st_name, gender, st_gpa)

Grades (st_id, c_id, s_id, grade)
st_id FOREIGN KEY REFERENCES Students
c_id,s_id FOREIGN KEY REFERENCES Sections

Classrooms (cl_id, capacity, location)

Teach (f_id, c_id, s_id)
f_id FOREIGN KEY REFERENCES Professors
c_id,s_id FOREIGN KEY REFERENCES Sections

NOTE: Primary keys are in red.

If I take this schema, appgini does not work with it. seems like I have to really mutate this schema in order for appgini to work...or am i missing something?

:)

abajaj11
Posts: 3
Joined: 2014-04-07 04:41

Re: Composite primary key and foreign key part of PK?

Post by abajaj11 » 2014-04-08 15:01

Here is the mutated schema:
Professors (ID,f_id, f_name, f_address, f_specialty, highest_degree)
Courses (ID,c_id, c_name, num_credits)
Sections (ID,Courses.ID, s_id, time_held, week_days_held, date_began, date_ended, Classrooms.ID)
Courses.ID FOREIGN KEY REFERENCES Courses, Classrooms.ID FOREIGN KEY REFERENCES Classrooms

Students (ID,st_id, st_name, gender, st_gpa)

Grades (ID, Student.ID, Sections.ID, grade)
Student.ID FOREIGN KEY REFERENCES Students
Sections.ID FOREIGN KEY REFERENCES Sections

Classrooms (ID, cl_id, capacity, location)

Teach (ID, Professors.ID, Sections.ID)
Professors.ID FOREIGN KEY REFERENCES Professors
Sections.ID FOREIGN KEY REFERENCES Sections

NOTE: Primary keys are in red.

In my opinion, I would need to mutate my earlier schema to this in order to use appGini. Am i right or am I missing something?

Post Reply