title: Delete a row from the table
body: <p>I created a schema in mysql InnoDB with the help of the following <code>.sql</code>:</p>
  
  <pre><code>CREATE DATABASE IF NOT EXISTS sailors;
  USE sailors;
  DROP TABLE IF EXISTS reserves;
  DROP TABLE IF EXISTS sailors;
  DROP TABLE IF EXISTS boats;
  
  CREATE TABLE sailors
  (
  sid    INTEGER NOT NULL ,
  sname  VARCHAR(20) NOT NULL ,
  rating INTEGER NULL ,
  age    DECIMAL(5,2) NULL, 
  CONSTRAINT sailors_pk PRIMARY KEY (sid)
  );
  
  CREATE TABLE boats
  (
  bid    INTEGER NOT NULL ,
  bname  VARCHAR(20) NOT NULL ,
  color  VARCHAR(10) NOT NULL ,
  CONSTRAINT boats_pk PRIMARY KEY (bid)
  );
  
  CREATE TABLE reserves
  (
  sid    INTEGER NOT NULL ,
  bid    INTEGER NOT NULL ,
  day    DATE NOT NULL ,
  CONSTRAINT reserves_pk PRIMARY KEY (sid,bid,day)
  , foreign key (sid) references sailors (sid)
  , foreign key (bid) references boats  (bid)
  );
  
  INSERT INTO sailors VALUES(22, 'Dustin', 7, 45.0);
  INSERT INTO sailors VALUES(29, 'Brutus', 1, 33.0);
  INSERT INTO sailors VALUES(31, 'Lubber', 8, 55.5);
  INSERT INTO sailors VALUES(32, 'Audy',   8, 25.5);
  INSERT INTO sailors VALUES(58, 'Rusty', 10, 35.5);
  INSERT INTO sailors VALUES(64, 'Horatio',7, 35.0);
  INSERT INTO sailors VALUES(71, 'Zorba', 10, 16.0);
  INSERT INTO sailors VALUES(74, 'Horatio',9, 35.0);
  INSERT INTO sailors VALUES(85, 'Art',    3, 25.5);
  INSERT INTO sailors VALUES(95, 'Bob',    3, 63.5);
  
  INSERT INTO boats VALUES(101, 'Interlake', 'blue');
  INSERT INTO boats VALUES(102, 'Interlake', 'red');
  INSERT INTO boats VALUES(103, 'Clipper',   'green');
  INSERT INTO boats VALUES(104, 'Marine',    'red');
  INSERT INTO boats VALUES(105, 'Clipper',   'white');
  
  INSERT INTO reserves VALUES(22, 101, DATE '2012-10-10');
  INSERT INTO reserves VALUES(22, 102, DATE '2012-10-10');
  INSERT INTO reserves VALUES(22, 103, DATE '2012-08-10');
  INSERT INTO reserves VALUES(22, 104, DATE '2012-07-10');
  INSERT INTO reserves VALUES(31, 102, DATE '2012-10-11');
  INSERT INTO reserves VALUES(31, 103, DATE '2012-06-11');
  INSERT INTO reserves VALUES(31, 104, DATE '2012-12-11');
  INSERT INTO reserves VALUES(64, 101, DATE '2012-05-09');
  INSERT INTO reserves VALUES(64, 102, DATE '2012-08-09');
  INSERT INTO reserves VALUES(74, 103, DATE '2012-08-09');
  </code></pre>
  
  <p>Now I want to delete all the information from all of the table about the sailor with the name <code>Lubber</code>. I do the following:</p>
  
  <pre><code>DELETE FROM sailors
  WHERE sname = 'Lubber';
  </code></pre>
  
  <p>and expect him to be deleted, but instead I am getting an error:</p>
  
  <pre><code>00:27:03    DELETE FROM sailors WHERE sname = 'Lubber'  Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`sailors`.`reserves`, CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`sid`) REFERENCES `sailors` (`sid`))    0.016 sec.
  </code></pre>
  
  <p>So, then I try another approach I know, but I fail here as well. Here is the approach and its failure.</p>
  
  <pre><code>DELETE sailors, reserves
  FROM sailors 
  INNER JOIN reserves ON (sailors.sid = reserves.sid)
  WHERE sname = 'Lubber';
  
  00:28:22    DELETE sailors, reserves FROM sailors  INNER JOIN reserves ON (sailors.sid = reserves.sid) WHERE sname = 'Lubber'   Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`sailors`.`reserves`, CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`sid`) REFERENCES `sailors` (`sid`))    0.000 sec
  </code></pre>
  
  <p>I am really stuck and do not know what else can I try. Will appreciate any help, thank you for the attention.</p>