MySQL : how to add foreign key
- by garcon1986
Hello,
I have the following code in mysql.
create table employee(
e_id int(10) not null auto_increment,
user_id int(10),
usertype_id default 1,
name varchar(50),
primary key (e_id)
);
create table relation(
r_id int(10) not null auto_increment,
user_id int(10) not null,
usertype_id int(10) not null,
interest_id int(10) not null,
primary key (id)
);
Firstly, i want user_id will have the same value as column e_id;
And then, i want to add user_id and usertype_id as an unity in table relation as a foreign key for user_id and usertype_id in table employee.
Do you know how to do that?
Thanks a lot.