title: MySQL FOREIGN KEY Constraints Syntax
body: <p>When I'm going to execute this code, I'm getting this error message:</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 'ADD CONSTRAINT <code>fk_pay_grade_scale</code> FOREIGN KEY <code>pay_scale_id</code>
    REFERENCES `pay_s' at line 11</p>
  </blockquote>
  
  <p>But I don't understand the problem. Your help is appreciated!</p>
  
  <pre>
  CREATE TABLE IF NOT EXISTS `pay_grades` (
      `pay_grade_id` int(20) NOT NULL,
    `pay_scale_id` tinyint(4) NOT NULL,
    `name` varchar(100) NOT NULL,
    `basic_salary` decimal(10,2) NOT NULL,  
    `status` int(2) NOT NULL DEFAULT '1',  
     PRIMARY KEY (`pay_grade_id`),
     INDEX (`pay_scale_id`, `pay_grade_id`),  
     ADD CONSTRAINT `fk_pay_grade_scale` FOREIGN KEY `pay_scale_id` REFERENCES `pay_scales`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
  
  CREATE TABLE IF NOT EXISTS `pay_scales` (
  `id` tinyint(4) NOT NULL,
    `name` varchar(100) NOT NULL,
    PRIMARY KEY(id)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </pre>