title: How to insert data when we have Relationship constraints in MySQL database
body: <p>I am following this <a href="https://rads.stackoverflow.com/amzn/click/com/0133970779" rel="nofollow noreferrer" rel="nofollow noreferrer">book</a> for my database class. The database has 6 tables. From the 6 of them I will post two of the tables.</p>
  
  <pre><code>/*EMPLOYEE Table */
  CREATE TABLE EMPLOYEE( 
      Fname VARCHAR(15) NOT NULL,
      Minit CHAR,
      Lname VARCHAR(15) NOT NULL,
      Ssn CHAR(9) NOT NULL,
      Bdate DATE,
      Address VARCHAR(30),
      Sex CHAR,
      Salary DECIMAL(10,2),
      Super_ssn CHAR(9),
      Dno INT NOT NULL,
      PRIMARY KEY (Ssn),
      FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn)
      FOREIGN KEY (Dno) REFERENCES DEPARTMENT(Dnumber) );
  </code></pre>
  
  <p>Employee table has a recursive relation to demonstrate "an employee is a supervisor of another employee". It also references the DEPARTMENT table  to show that an employee works in a department. Below is the schema for the DEPARTMENT table.</p>
  
  <pre><code>CREATE TABLE DEPARTMENT( 
      Dname VARCHAR(15) NOT NULL,
      Dnumber INT NOT NULL,
      Mgr_ssn CHAR(9) NOT NULL,
      Mgr_start_date DATE,
      PRIMARY KEY (Dnumber),
      UNIQUE (Dname),
      FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn) 
      );
  </code></pre>
  
  <p>The DEPARTMENT table references the employee table to show that an employee manages a department.
  When inserting data such as</p>
  
  <pre><code>    insert into EMPLOYEE values
      ('John','B','Smith','123456789','1965-01-09','731 Fondren, Houston, TX',
       'M',30000,'333445555',5);
  </code></pre>
  
  <p>We wont be able to execute the above query because there is a referential integrity <code>FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn)</code>.  Same if i try the query below</p>
  
  <pre><code>insert into department values ('Research',5,'333445555','1988-05-22');
  </code></pre>
  
  <p>The above query wont execute because there is no data in employee table. My question is should we first insert the data and then alter the table and enforce referential integrity constraints. Or is there a way around. Your suggestions/advice will be appreciated. Thank You.</p>