Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my database table need a primary key?
    primarykey
    data
    text
    <p>In my database I have a list of users with information about them, and I also have a feature which allows a user to add other users to a shortlist. My user information is stored in one table with a primary key of the user id, and I have another table for the shortlist. The shortlist table is designed so that it has two columns and is basically just a list of pairs of names. So to find the shortlist for a particular user you retrieve all names from the second column where the id in the first column is a particular value.</p> <p>The issue is that according to many sources such as this <a href="https://stackoverflow.com/questions/840162/should-each-and-every-table-have-a-primary-key">Should each and every table have a primary key?</a> you should have a primary key in every table of the database.</p> <p>According to this source <a href="http://www.w3schools.com/sql/sql_primarykey.asp" rel="nofollow noreferrer">http://www.w3schools.com/sql/sql_primarykey.asp</a> - a primary key in one which uniquely identifies an entry in a database. So my question is:</p> <ol> <li><p>What is wrong with the table in my database? Why does it need a primary key?</p></li> <li><p>How should I give it a primary key? Just create a new auto-incrementing column so that each entry has a unique id? There doesn't seem much point for this. Or would I somehow encapsulate the multiple entries that represent a shortlist into another entity in another table and link that in? I'm really confused.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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