MySQL Forums
Forum List  »  InnoDB

Re: Foreign Key Different Database
Posted by: Sebastián Gómez
Date: March 11, 2008 07:41AM

i just did this and it worked

create database db1;

use db1;

CREATE TABLE `historial` (
`codh` smallint(5) unsigned NOT NULL auto_increment,
PRIMARY KEY (`codh`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

create database db2;

use db2;

CREATE TABLE t1 (
id tinyint(3) unsigned NOT NULL auto_increment,
micod smallint(5) unsigned default NULL,
PRIMARY KEY (id),
KEY micod (micod),
CONSTRAINT t1_ibfk_1 FOREIGN KEY (micod) REFERENCES db1.historial (codh) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE t2 (
id tinyint(3) unsigned NOT NULL auto_increment,
micod2 smallint(5) unsigned default NULL,
PRIMARY KEY (id),
KEY micod2 (micod2)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

alter table t2 add foreign key FK_t2(micod2) references db1.historial(codh) on delete cascade on update cascade;

/*-------------------*/

i'm using 4.1.10a by the way

cheers!

Options: ReplyQuote


Subject
Views
Written By
Posted
18049
April 27, 2007 08:52AM
Re: Foreign Key Different Database
21739
March 11, 2008 07:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.