title: How To Design A Database With Different Types of Products
body: <p>I have a store that currently sells three different types of items: Video Game, Console, and Cables. I am trying to figure out how to design a single table that would be used by these three items.</p>
  
  <p>I was thinking that each type would have the following properties:</p>
  
  <pre><code>Video Game
  - name
  - console
  
  Console
  - name
  
  Cable
  - name
  </code></pre>
  
  <p>I came up with the design:</p>
  
  <pre><code>Product
  - Type
  - Name
  - Console
  </code></pre>
  
  <p>So it would translate into something like:</p>
  
  <pre><code>id | type    | name          | console
  ---+---------+---------------+---------
   1 | game    | Goldeneye     | N64
   2 | console | SNES          | null
   3 | cable   | HDMI          | null
   4 | game    | Smash Bros    | Wii
  </code></pre>
  
  <p>But the console column would always be null for <code>console</code> and <code>cable</code> typed products. Furthermore, I think this design can be very restrictive if I decide to sell another type of product that requires another column (ie - TV monitors and include screen size).</p>
  
  <p>Is there a better way to design my table?</p>
  
  <p>I looked around on SO and this solution seemed ideal: <a href="https://stackoverflow.com/a/20793237/1054937">https://stackoverflow.com/a/20793237/1054937</a>. I would create a generic Product table that references an Attribute table. In that case the DB would not be able to enforce the Attirbutes (ie - all games must have a console attribute).</p>