Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes to all your questions. I agree with your assertions that you should "<em>expose some other value to the web app that can be translated back to the primary key</em>"</p> <p>You can open yourself up to potential problems otherwise.</p> <p><strong>Edit</strong></p> <p>Regarding the comment that "<em>there is no reason to take the penalty hit for trivial keys. Look in your browser's URL right now, I bet you see a key!</em>". </p> <p>I understand what you're saying and, yes, I do see the key in the SO URL and agree it probably does refer to a database PK. I concede in instances like this it's probably OK if there's not a better alternative. </p> <p>I'd still prefer to expose something other than a PK - something with semantic value. The title of the question is also in the URL, but since this would be hard to verify as unique (or pass between users verbally) it can't be used reliably on it's own. </p> <p>When looking at the "tag" URLs however (i.e. <a href="https://stackoverflow.com/questions/tagged/java+j2ee">https://stackoverflow.com/questions/tagged/java+j2ee</a>), the PKs are not exposed and the tag names are used instead. Personally, I prefer that approach and would strive for that.</p> <p>I also wanted to add that the data a PK points at can sometimes change with time. I've worked on a system where a table was filled with info from an offline process - i.e. monthly statistics where the DB table contents dropped at the end of the month and was repopulated with new data. </p> <p>If the data is added to the db in a different order, the PKs for specific data points would change, and any saved bookmarks from a previous month to that data would now point at a different set of data. </p> <p>This is one instance where exposing a PK would "break" an app unrelated to the security of the app. Not so with a generated key.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload