MySQL : how to add foreign key
Posted
by garcon1986
on Stack Overflow
See other posts from Stack Overflow
or by garcon1986
Published on 2010-02-23T16:18:00Z
Indexed on
2010/05/20
20:20 UTC
Read the original article
Hit count: 294
mysql
|foreign-key
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.
© Stack Overflow or respective owner