Forum Moderators: open

Message Too Old, No Replies

Primary key necessary?

Many-to-many third table

         

andrewheiss

10:00 pm on Jun 12, 2008 (gmt 0)

10+ Year Member



I have a many-to-many system in my database with two tables (classes and dates) that are well formed with a primary key and everything. I have a third table, classes_dates that combines the two:

Table classes = id_class, class_title, etc.
Table dates = id_date, date, etc.
Table classes_dates = id, fk_class, fk_date

I currently have a pk set in classes_dates--id--but want to know if that's really necessary? It's a dynamic table - every time a class gets updated, I delete every row where fk_class = id_class and insert the new classes and dates. Every time I do this the auto-increment value goes up, seemingly unnecessary.

Will the table survive without a primary key, or should I keep it just becuase?

webfoo

12:34 am on Jun 15, 2008 (gmt 0)

10+ Year Member



It's always good to have a primary key by which to identify each entry uniquely. Since it is possible that you could have two or more identical entries, it's good to have a unique identifier. The auto-increment is one more than the highest value the field has ever contained.

I would leave the primary key in, just as good form. Unless it's causing problems, just follow the old saying: "If it ain't broke, don't fix it."