Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Short answer: <strong>yes</strong>.</p> <p>Long answer:</p> <ul> <li>You need your table to be joinable on something</li> <li>If you want your table to be clustered, you need some kind of a primary key.</li> <li>If your table design does not need a primary key, rethink your design: most probably, you are missing something. Why keep identical records?</li> </ul> <p>In MySQL, the InnoDB storage engine always creates a primary key if you didn't specify it explicitly, thus making an extra column you don't have access to.</p> <p>Note that a primary key can be composite.</p> <p>If you have a many-to-many link table, you create the primary key on all fields involved in the link. Thus you ensure that you don't have two or more records describing one link.</p> <p>Besides the logical consistency issues, most RDBMS engines will benefit from including these fields in a unique index.</p> <p>And since any primary key involves creating a unique index, you should declare it and get both logical consistency and performance.</p> <p>See this article in my blog for why you should always create a unique index on unique data:</p> <ul> <li><a href="http://explainextended.com/2009/04/23/making-an-index-unique/" rel="noreferrer"><strong>Making an index UNIQUE</strong></a></li> </ul> <p><strong>P.S.</strong> There are some <em>very, very</em> special cases where you don't need a primary key.</p> <p>Mostly they include log tables which don't have <em>any</em> indexes for performance reasons.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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