title: MYSQL insert with foreign key
body: <p>How do i go about inserting a foreign key during insertion that references the relationship to another table. </p>
  
  <p>I am trying to insert the CD 'duck' with an existing band in the band table.</p>
  
  <p><code>INSERT INTO CD (TITLE, YEAR) VALUES ('Ducks', 2013);</code> </p>
  
  <p>My application is in Java and has 2 classes:</p>
  
  <pre><code> Band class:
      String name
      int year
      ArrayList&lt;String&gt; members
  
   CD class:
      String title
      int year
  </code></pre>
  
  <p>SQL tables</p>
  
  <pre><code>CREATE TABLE BAND 
  (
     BAND_ID INT NOT NULL AUTO_INCREMENT,
     NAME VARCHAR(50),
     YEAR INT,
     PRIMARY KEY(BAND_ID)
  );
  
  CREATE TABLE CD
  (
     CD_ID INT NOT NULL AUTO_INCREMENT,
     TITLE VARCHAR(50),
     YEAR INT,
     B_ID INT,
     PRIMARY KEY(CD_ID),
     FOREIGN KEY(B_ID) REFERENCES BAND(BAND_ID)
  );
  
  CREATE TABLE MEMBER
  (
     MEMBER_ID INT NOT NULL AUTO_INCREMENT,
     NAME VARCHAR(50),
     B_ID INT,
     PRIMARY KEY(MEMBER_ID),
     FOREIGN KEY(B_ID) REFERENCES BAND(BAND_ID)
  );
  </code></pre>