Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 570293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:23:09+00:00 2026-05-13T13:23:09+00:00

While I’ve been writing php for a long time, it was always a skill

  • 0

While I’ve been writing php for a long time, it was always a skill I learnt myself and I’ve just hit a minor crisis of confidence over table joins!

Assuming a MySQL db auth containing MyISAM tables users and permissions:

users
- id (auto increment)
- email

permissions
- id (auto increment)
- name

To join these tables in a many-to-many (or one-to-many), I’ve always used bridge tables like so:

user_permissions
- id (auto increment)
- user_id
- permission_id

(I know innoDB is capable of relationships, but it’s also more complex and hogs more memory, so for the purpose of the q I’d like to stay with myISAM)

My particular question is this: is it wise to join the tables using the auto-incremented key, or should I be generating my own additional key?

I’m aware that problems could occur if a table gets corrupted and I have to rebuild or if I begin mirroring to two dbs and the keys get out-of-sync.

I’m also aware that if I generate a unique hash for each row (to be used in joins) then there is the overhead of generating a hash and checking that it is new before every data insert.

How does everyone else do it? Are these issues things you have seen in practical situations?

Thanks for your time!

Adam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:23:10+00:00Added an answer on May 13, 2026 at 1:23 pm

    This is generally a decision between using surrogate keys (made-up or automatically assigned values that have no meaning beyond being unique), and natural keys (keys that have some semantic meaning with respect to the entity being stored, like a name, or bank account #).

    in your case, it’s not clear there is any natural key that would work (every aspect of the user table could change – name change after marriage, etc.). you would want a natural key if there’s no possibility of the key ever morphing while still keeping the relationships. an example would be something like element names (Au, He, Es, etc.) in the periodic table of elements (which are unlikely to change aside from adding new ones, but hey, anything could happen…).

    as for data corruption, backups are really the best protection because anything can get corrupted. and in typical operations, you can always preserve the primary key whenever migrating or synchronizing. using an elaborately complex surrogate key instead of the auto increment provided by the db would be more risky because it complicates inserts (you have to ensure its unique, and possibly handle collisions in a transaction safe way)… and indeed an elaborately generated surrogate key wouldn’t help in the case of data corruption (no way to correlate it with the record).

    a natural PK on say the user’s email would be a lot of overhead – have to update every relationship whenever the email changes, swapping email addresses between 2 accounts is complicated, indexes are much less efficient on wide values instead of ints. the trade-offs tilt in favor of the auto increment key.

    a good writeup is here:

    http://decipherinfosys.wordpress.com/2007/02/01/surrogate-keys-vs-natural-keys-for-primary-key/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 477k
  • Answers 477k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no easy way to do this. This is… May 16, 2026 at 5:15 am
  • Editorial Team
    Editorial Team added an answer This is a common mistake, Use stage.stageWidth and stage.stageHeight. May 16, 2026 at 5:15 am
  • Editorial Team
    Editorial Team added an answer DOMDocument has lots of excellent methods for accessing, updating and… May 16, 2026 at 5:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.