Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Primary/Foreign Key Field in this Database Model?

I'm looking at this database model and I'm confused about the "PF" in some of the tables. My understanding is that the PF is a "Primary/Foreign key" which could also be a composite key. I understand this situation for a many-to-many relationship, but what about situations such as the Menu_Courses table? The primary key would obviously be an auto-incremented column of type int, but what about the menu_id field? How would that be implemented in a database such as SQL Server?

The author also explains PF fields on this page: http://www.databaseanswers.org/tutorial4_db_schema/tutorial_slide_5.htm

http://www.databaseanswers.org/data_models/recipes/index.htm

like image 718
Robert Avatar asked Dec 31 '12 20:12

Robert


1 Answers

The way I understand it is that these fields are primary keys on the table they are defined on, and at the same time they are foreign keys to other tables.

menu_courses has the reference to suggested_menus through menu_id and combined with course_number makes the primary key - that is each menu/course number combination is unique and uniquely identifies a row on the table.

You would normally implement this as a foreign key field on the suggested_menus table.

like image 131
Oded Avatar answered Sep 25 '22 14:09

Oded