How to restrict insert on adding self-referencing rows in a recursive relation table (a table contains foreign key points itself)?
mysql> SELECT * FROM Employee;
+-----+------+-------------+------+
| SSN | name | designation | MSSN |
+-----+------+-------------+------+
| 1 | A | OWNER | NULL |
| 2 | B | BOSS | 1 |
| 3 | C | WORKER | 2 |
| 4 | D | BOSS | 2 |
| 5 | E | WORKER | 4 |
| 6 | F | WORKER | 1 |
| 7 | G | WORKER | 4 |
| 8 | H | BOSS | 8 |
+-----+------+-------------+------+
8 rows in set (0.00 sec)
An employee can't be the BOSS of themselves. Hence
mysql> INSERT INTO Employee VALUES ("8", "H", "BOSS", "8");
Query OK, 1 row affected (0.04 sec)
should be declined by some constraint. How can one add such a constraint?
If possible suggest without using a trigger.