I have one employee table:
create table employee
(number integer primary key,
name varchar(20),
salary integer,
manager integer,
birthyear integer,
startyear integer);
Where the manager column is the employee number of the employees manager, i.e. a couple of rows would look something like this:
number | name | salary | manager | birthyear | startyear |
32 | Smythe, Carol | 9050 | 199 | 1929 | 1967 |
33 | Hayes, Evelyn | 10100 | 199 | 1931 | 1963 |
35 | Evans, Michael | 5000 | 32 | 1952 | 1974 |
So to clarify, Michael Evans manager is Carol Smythe. And two more things, there are no foreign key constraints on this table and there are a couple of NULL values in the manager column. Now, I would like to create a Managers table which contains all managers. I would do something like this;
create table Mgr(
Mgr_id INTEGER PRIMARY KEY,
bonus INTEGER,
FOREIGN KEY (Mgr_id) REFERENCES employee(manager));
BUT; this doesn´t work and I get an error. Can someone please explain why? Have searched for an answer but can´t find any good explanation. Thanks in advance.
ERROR:
ERROR 1005 (HY0000): Can´t create table johnson.mgr (errno: 150)