Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>NULL values</strong></p> <blockquote> <p>It also means item will have 5 ids including its own. This all cause null values (apparently a big no no, which I can understand) because if place and price are optional and are not used on one entry to the items table I will have a null value there</p> </blockquote> <p>Personally I think this is one situation where <code>NULL</code> values are perfect, and I certainly wouldn't have any doubts about putting this into my database design.</p> <p>One way I've seen others achieve the same thing without <code>NULL</code> values is to create a record in the optional tables (place and price in your example) with an ID of 0 that signifies there's no related record - but this just makes 10 times more work for the developer of the application to filter these records out - it's FAR easier to do a join and if you don't get any records back, there are no related records in the optional table.</p> <p>Just remember to do a <code>LEFT</code> or <code>RIGHT OUTER</code> join if you want to return <code>Item</code>s regardless of whether they have a <code>Place</code> or <code>Price</code> associated (you'll get <code>NULL</code> values in the optional table columns for <code>Item</code>s that don't have associated records) and an <code>INNER</code> join if you <strong>only</strong> want the <code>Item</code>s that <strong>do</strong> have an associated optional record.</p> <p><strong>Composite Keys</strong></p> <p>A composite key is a key in a table that's made up of more than one column. If each of your <code>Person</code>, <code>Item</code>, <code>Place</code> and <code>Price</code> all have an ID (even if it's just an auto-incrementing number) you won't need a composite key - just a primary key column in each table, and a foreign key column in the <code>Item</code> table for each related table - e.g. <code>item_id</code>, <code>person_id</code>, <code>place_id</code>, <code>price_id</code>. You state that <code>Item</code> has its own ID, so you shouldn't need a composite key - just a primary key on the <code>item_id</code> column.</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