title: why is mysql allowing to delete records referenced by a foreign key?
body: <p>My question is why i am able to delete records from dept table, which have corresponding records present in emp table.</p>
  
  <p>For example , i am able to delete record in dept table where deptno = 10, while a record in emp table is referencing that using the foreign key.</p>
  
  <pre><code>mysql&gt; select * from emp;
  +-------+-------+---------+------+----------+------+------+--------+
  | empno | ename | job     | mgr  | hiredate | sal  | comm | deptno |
  +-------+-------+---------+------+----------+------+------+--------+
  |  7698 | BLAKE | MANAGER | 7839 | NULL     | 2850 | NULL |     30 |
  |  7782 | CLARK | MANAGER | 7839 | NULL     | 2450 | NULL |     10 |
  +-------+-------+---------+------+----------+------+------+--------+
  2 rows in set (0.00 sec)
  
  mysql&gt; select * from dept;
  +--------+------------+----------+
  | deptno | dname      | loc      |
  +--------+------------+----------+
  |     10 | ACCOUNTING | NEW YORK |
  |     20 | RESEARCH   | DALLAS   |
  |     30 | SALES      | CHICAGO  |
  |     40 | OPERATIONS | BOSTON   |
  +--------+------------+----------+
  4 rows in set (0.00 sec)
  
  
  mysql&gt; delete from dept where deptno = 10;
  Query OK, 1 row affected (0.00 sec)
  </code></pre>
  
  <p>This is my table structure </p>
  
  <pre><code>CREATE TABLE dept( deptno int, dname varchar(14), loc varchar(13), PRIMARY KEY (deptno));
  
  CREATE TABLE emp( empno int, ename varchar(10), job varchar(9), mgr int, hiredate date, sal int, comm int, deptno int, PRIMARY KEY (empno),FOREIGN KEY (deptno) REFERENCES dept (deptno));
  
  INSERT INTO dept VALUES(10,'ACCOUNTING','NEW YORK');
  INSERT INTO dept VALUES(20,'RESEARCH','DALLAS');
  INSERT INTO dept VALUES(30,'SALES','CHICAGO');
  INSERT INTO dept VALUES(40,'OPERATIONS','BOSTON');
  
  
  INSERT INTO emp
  VALUES( 7698,
          'BLAKE',
          'MANAGER',
          7839,
          STR_TO_DATE('1-5-1981','dd-mm-yyyy'),
          2850,
          NULL,
          30);
  
  
  INSERT INTO emp
  VALUES( 7782,
          'CLARK',
          'MANAGER',
          7839,
          STR_TO_DATE('9-6-1981','dd-mm-yyyy'),
          2450,
          NULL,
          10);
  </code></pre>
  
  <p>Thanks in advance . </p>
  
  <p>This is my show table structure for emp </p>
  
  <pre><code>mysql&gt; show create table dept;
  +-------+---------------------------------------------------
  | Table | Create Table
  +-------+---------------------------------------------------
  | dept  | CREATE TABLE `dept` (
    `deptno` int(11) NOT NULL DEFAULT '0',
    `dname` varchar(14) DEFAULT NULL,
    `loc` varchar(13) DEFAULT NULL,
    PRIMARY KEY (`deptno`)
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
  +-------+---------------------------------------------------
  </code></pre>