title: MySQL Relationships
body: <p>I am trying to figure out how to structure this database. I have used Apple's core data before just fine, I'm just working on a different project now that requires MySQL. I am very new to MySQL so please go easy on me. :)</p>
  
  <p>For this example, let's say I have three tables, <code>User</code>, <code>Device</code>, and <code>Location</code>. Drawing it out, a <code>Location</code> can have many <code>Device</code>s, but the <code>Device</code> can only have one <code>Location</code>; Each <code>User</code> has its primary key, <code>UserID</code>, of which I need to use to fetch the correct information.</p>
  
  <p>So how do I create a relationship like this here? I've heard of creating an index and a foreign key and I'm not sure how they work exactly. </p>
  
  <p>In the end, what I need to do is be able to access the <code>User</code>'s specific table and view all of the <code>Locations</code> associated with that <code>User</code>. I will also need to be able to add a <code>Device</code> at a certain <code>Location</code> for a certain <code>User</code>.</p>
  
  <p>Again, please forgive me as I'm trying to wrap my head around MySQL. I am using HeidiSQL to do my database editing.</p>