I'm kinda new at mysql database so I'm sorry if this is kinda noob question... if I have 2 database, database a and database b.. then I created 1 table in each database.. can I use the table in database b to connect to the table in database a to have a foreign and primary key? or it can only be connected between tables on the same database?
Asked
Active
Viewed 123 times
1 Answers
0
I think your question is "can foreign key columns reference columns in another database." The answer is "yes they can."
CREATE DATABASE a; USE a;
CREATE TABLE a1 (id int not null auto_increment primary key);
CREATE DATABASE b; USE b;
CREATE TABLE b1 (id int, aid int, foreign key (aid) references a.a1 (id));

Explosion Pills
- 188,624
- 52
- 326
- 405
-
Thanks for answering... I will try it.. thanks for the new knowledge :) – John Jun 01 '13 at 19:33