change a column type and innodb foreign key constraints

2005-03-16 Thread rich
Hi,
I have a column 'id' within a table :
CREATE TABLE `reference` (
 *`*id*`* smallint(5) unsigned NOT NULL auto_increment,
 `study_name` text,
 `author` text NOT NULL,
 `date` date NOT NULL default '-00-00',
 `reference` varchar(250) NOT NULL default '',
 `title` varchar(250) NOT NULL default '',
 `pmid` int(15) default NULL,
 `project` varchar(35) default NULL,
 `abstract` text,
 `datasource` smallint(5) unsigned default NULL,
 PRIMARY KEY  (`id`),
 KEY `id` (`id`)
) TYPE=InnoDB

that i need to change from smallint to int
There are a number of foreign key constraints from other columns in other 
tables on this column:
eg
CREATE TABLE `monogenic` (
 `id` smallint(5) unsigned NOT NULL default '0',
 `exp_design` varchar(50) default NULL,
 `disease` varchar(50) default NULL,
 `omim` varchar(20) default NULL,
 `phenotype_ID` smallint(5) unsigned NOT NULL default '0',
 `pop` varchar(200) default NULL,
 `num_peds` int(7) unsigned default NULL,
 `affected` int(7) unsigned default NULL,
 `unaffected` int(7) unsigned default NULL,
 `mut_type` varchar(50) default NULL,
 `mut_loc` varchar(50) default NULL,
 `gene_ID` mediumint(8) unsigned NOT NULL default '0',
 PRIMARY KEY  (`id`,`gene_ID`),
 KEY `phenotype_ID` (`phenotype_ID`),
 KEY `gene_ID` (`gene_ID`),
 CONSTRAINT `0_178` FOREIGN KEY (`gene_ID`) REFERENCES `gene` (`id`),
 CONSTRAINT `0_179` FOREIGN KEY (`id`) REFERENCES `reference` (`id`) ON DELETE 
CASCADE
) TYPE=InnoDB

Upon trying to modify the id columns in the reference table, i'm getting the 
following
mysql alter table reference modify id int;
ERROR 1025: Error on rename of './nugenob/#sql-2ed1_e001' to 
'./nugenob/reference' (errno: 150)
mysql
It looks from googling as though I need to drop all foreign key constraints 
on this column, perform the change and then reestablish the foreign keys. Could 
anyone confirm or advise of a better solution?
cheers
Rich

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


Re: change a column type and innodb foreign key constraints

2005-03-16 Thread Gabriel PREDA
 It looks from googling as though I need to drop all foreign key
constraints on this column, perform the change and then reestablish the
foreign keys. Could anyone confirm or advise of a better solution?

That is the way ! :)
You need to drop the constrains...
Alter  `reference` and make `id` INT
You will need to alter the `monogenic` table as well... making it's `id` INT
also...
Recreate constrains...

Though... I do not know if you need to drop ALL constrains or only the one
that ties the tables:
thisCONSTRAINT `0_179` FOREIGN KEY (`id`) REFERENCES `reference`
(`id`) ON DELETE CASCADE/this

Gabriel PREDA
www.amr.ro
www.lgassociations.info
www.falr.ro
dev.falr.ro


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: change a column type and innodb foreign key constraints

2005-03-16 Thread SGreen
Gabriel PREDA [EMAIL PROTECTED] wrote on 03/16/2005 06:12:14 AM:

  It looks from googling as though I need to drop all foreign key
 constraints on this column, perform the change and then reestablish the
 foreign keys. Could anyone confirm or advise of a better solution?
 
 That is the way ! :)
 You need to drop the constrains...
 Alter  `reference` and make `id` INT
 You will need to alter the `monogenic` table as well... making it's `id` 
INT
 also...
 Recreate constrains...
 
 Though... I do not know if you need to drop ALL constrains or only the 
one
 that ties the tables:
 thisCONSTRAINT `0_179` FOREIGN KEY (`id`) REFERENCES `reference`
 (`id`) ON DELETE CASCADE/this
 
 Gabriel PREDA
 www.amr.ro
 www.lgassociations.info
 www.falr.ro
 dev.falr.ro

Yes, Gabriel is right. You do not have to remove ALL of your foreign 
constraints, only those that include the column you need to change. 

Imagine the situation that would occur if you had been able to 
successfully change the definition of the ID column and you didn't 
un-define your foreign keys or change any of your other referencing 
columns.  You would have had a relationship that was trying to enforce 
equality between an int on one side and a smallint on the other. Clearly 
that would be an illegal FK constraint, right? That's why you were not 
permitted to change the column as it would have made your existing foreign 
keys illegal.

Follow Gabriel's advice, drop the FKs that reference the column you want 
to change, modify the fields on BOTH ends of your FKs to have matching 
datatypes, then re-establish your FKs. It may be a little work but that's 
just part of the job.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

InnoDB foreign key constraints

2004-07-15 Thread Glenn Sequeira
Hello,
Are there any plans to implement foreign keys with deferred integrity 
constraint checking in the InnoDB storage engine in a future release of 
the MySQL Server?

Many thanks,
- glenn
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


InnoDB foreign key constraints

2002-06-10 Thread Markus Lervik


Hello list!

I'm having a bit of trouble getting foreign key constraints to work.
I'm running MySQL 2.23.50-Max.

Here's what I got:

mysql SHOW CREATE TABLE conn\G
*** 1. row ***
   Table: conn
Create Table: CREATE TABLE `conn` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `wall_nr` int(10) unsigned NOT NULL default '0',
  `hub_switch` varchar(20) NOT NULL default '',
  `comp_name` varchar(80) NOT NULL default '',
  `name_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name_id` (`name_id`),
  UNIQUE KEY `comp_name` (`comp_name`),
  KEY `conn_idx` (`name_id`)
) TYPE=InnoDB
1 row in set (0.00 sec)

mysql SHOW CREATE TABLE ip_name_tbl\G
*** 1. row ***
   Table: ip_name_tbl
Create Table: CREATE TABLE `ip_name_tbl` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `comp_loc` smallint(5) unsigned NOT NULL default '0',
  `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
  `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
  `IP` varchar(15) default NULL,
  `MAC` varchar(17) NOT NULL default '',
  `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
  `name_id` int(11) NOT NULL default '0',
  `comments` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name_id` (`name_id`),
  KEY `ip_idx` (`name_id`)
) TYPE=InnoDB
1 row in set (0.00 sec)

Here's what I get:

mysql ALTER TABLE ip_name_tbl
- ADD CONSTRAINT FOREIGN KEY (name_id)
- REFERENCES conn(name_id)
- ON DELETE CASCADE;
ERROR 1005: Can't create table './koneet/#sql-355_4.frm' (errno: 150)

I know error 1005 with an errno 150 means the foreign key would be incorrectly
formed, but I can't just figure out what's wrong. 
I've been reading TFM, and the sentence there must be an index where the 
foreign key and the referenced key are listed as the first columns seems to 
have something to do with my problem, I just find the above a bit... well... 
cryptic. If anyone could lend me a hand, I'd be more than happy.

Thank's in advance!

Cheers,
Markus

-- 
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: InnoDB foreign key constraints

2002-06-10 Thread Kiss Dániel

First of all the referenced key must be on PRIMARY KEY.

But I've seen in your table definition a quite strange thing. You have a 
UNIQUE and an ORDINARY key definition on the same field.
Here:

...
   UNIQUE KEY `name_id` (`name_id`), - THIS IS THE FIRST DEFINITION
   UNIQUE KEY `comp_name` (`comp_name`),
   KEY `conn_idx` (`name_id`) - AND THIS IS THE SECOND ONE
...

At 10:59 2002.06.10. +0300, you wrote:

Hello list!

I'm having a bit of trouble getting foreign key constraints to work.
I'm running MySQL 2.23.50-Max.

Here's what I got:

mysql SHOW CREATE TABLE conn\G
*** 1. row ***
Table: conn
Create Table: CREATE TABLE `conn` (
   `id` int(10) unsigned NOT NULL auto_increment,
   `wall_nr` int(10) unsigned NOT NULL default '0',
   `hub_switch` varchar(20) NOT NULL default '',
   `comp_name` varchar(80) NOT NULL default '',
   `name_id` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name_id` (`name_id`),
   UNIQUE KEY `comp_name` (`comp_name`),
   KEY `conn_idx` (`name_id`)
) TYPE=InnoDB
1 row in set (0.00 sec)

mysql SHOW CREATE TABLE ip_name_tbl\G
*** 1. row ***
Table: ip_name_tbl
Create Table: CREATE TABLE `ip_name_tbl` (
   `id` int(10) unsigned NOT NULL auto_increment,
   `comp_loc` smallint(5) unsigned NOT NULL default '0',
   `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
   `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
   `IP` varchar(15) default NULL,
   `MAC` varchar(17) NOT NULL default '',
   `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
   `name_id` int(11) NOT NULL default '0',
   `comments` text,
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name_id` (`name_id`),
   KEY `ip_idx` (`name_id`)
) TYPE=InnoDB
1 row in set (0.00 sec)

Here's what I get:

mysql ALTER TABLE ip_name_tbl
 - ADD CONSTRAINT FOREIGN KEY (name_id)
 - REFERENCES conn(name_id)
 - ON DELETE CASCADE;
ERROR 1005: Can't create table './koneet/#sql-355_4.frm' (errno: 150)

I know error 1005 with an errno 150 means the foreign key would be incorrectly
formed, but I can't just figure out what's wrong.
I've been reading TFM, and the sentence there must be an index where the
foreign key and the referenced key are listed as the first columns seems to
have something to do with my problem, I just find the above a bit... well...
cryptic. If anyone could lend me a hand, I'd be more than happy.

Thank's in advance!

Cheers,
Markus

--
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: InnoDB foreign key constraints

2002-06-10 Thread Me

Heya!

You need an INDEX.

Try doing this first :

alter table ip_name_tbl add INDEX(name_id);
And add then your constraint.

EG


mysql SHOW CREATE TABLE ip_name_tbl\G
*** 1. row ***
   Table: ip_name_tbl
Create Table: CREATE TABLE `ip_name_tbl` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `comp_loc` smallint(5) unsigned NOT NULL default '0',
  `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
  `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
  `IP` varchar(15) default NULL,
  `MAC` varchar(17) NOT NULL default '',
  `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
  `name_id` int(11) NOT NULL default '0',
  `comments` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name_id` (`name_id`),
  KEY `ip_idx` (`name_id`)
) TYPE=InnoDB
1 row in set (0.00 sec)

Here's what I get:

mysql ALTER TABLE ip_name_tbl
- ADD CONSTRAINT FOREIGN KEY (name_id)
- REFERENCES conn(name_id)
- ON DELETE CASCADE;
ERROR 1005: Can't create table './koneet/#sql-355_4.frm' (errno: 150)

I know error 1005 with an errno 150 means the foreign key would be
incorrectly
formed, but I can't just figure out what's wrong.
I've been reading TFM, and the sentence there must be an index where the
foreign key and the referenced key are listed as the first columns seems to
have something to do with my problem, I just find the above a bit... well...
cryptic. If anyone could lend me a hand, I'd be more than happy.

Thank's in advance!

Cheers,
Markus

--
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail
[EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: InnoDB foreign key constraints

2002-06-10 Thread Markus Lervik

On Monday 10 Jun 2002 11:17 am, you wrote:
 First of all the referenced key must be on PRIMARY KEY.

...which means my 'id' -field can't be a primary key, right?

 But I've seen in your table definition a quite strange thing. You have a
 UNIQUE and an ORDINARY key definition on the same field.
 Here:

UNIQUE KEY `name_id` (`name_id`), - THIS IS THE FIRST DEFINITION
UNIQUE KEY `comp_name` (`comp_name`),
KEY `conn_idx` (`name_id`) - AND THIS IS THE SECOND ONE

I've probably messed something up while fooling around with indexes and trying 
to get it to work. Now, I took the advices I got, but I still can't get it to 
work. I altered the table to make the 'id' -field an ordinary index, and 
changed the name_id -field to a primary key, without luck. So now my
SHOW CREATE TABLE gives:

mysql show create table ip_name_tbl\G
*** 1. row ***
   Table: ip_name_tbl
Create Table: CREATE TABLE `ip_name_tbl` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `comp_loc` smallint(5) unsigned NOT NULL default '0',
  `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
  `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
  `IP` varchar(15) default NULL,
  `MAC` varchar(17) NOT NULL default '',
  `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
  `name_id` int(11) NOT NULL default '0',
  `comments` text,
  PRIMARY KEY  (`name_id`),
  KEY `id` (`id`)
) TYPE=InnoDB

...and

mysql show create table conn\G
*** 1. row ***
   Table: conn
Create Table: CREATE TABLE `conn` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `wall_nr` int(6) unsigned NOT NULL default '0',
  `hub_switch` varchar(20) NOT NULL default '',
  `comp_name` varchar(50) NOT NULL default '',
  `name_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`name_id`),
  KEY `id` (`id`)
) TYPE=InnoDB


and, again:

mysql ALTER TABLE ip_name_tbl
- ADD CONSTRAINT FOREIGN KEY (name_id)
- REFERENCES conn (name_id)
- ON DELETE CASCADE;
ERROR 1005: Can't create table './koneet/#sql-355_4.frm' (errno: 150)

*sigh*

Cheers,
Markus

-- 
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: InnoDB foreign key constraints

2002-06-10 Thread Markus Lervik

On Monday 10 Jun 2002 11:44 am, Markus Lervik wrote:

 mysql show create table ip_name_tbl\G
 *** 1. row ***
Table: ip_name_tbl
 Create Table: CREATE TABLE `ip_name_tbl` (
[snip]
   `name_id` int(11) NOT NULL default '0',
[snip]

 mysql show create table conn\G
 *** 1. row ***
Table: conn
 Create Table: CREATE TABLE `conn` (
[snip]
   `name_id` int(10) unsigned NOT NULL default '0',
[snip]

Ok, thank's to Jocelyn the problem is solved and can be seen above.
Kinda makes sence that both fields should be the same. : )
Slipped my attention ; )


Cheers,
Markus

-- 
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: InnoDB foreign key constraints

2002-06-10 Thread Wouter van Vliet

What I think, is that your syntax for creating the primary key is slightly
incorrect. I'm not sure if this is also true vor MySQL but I got teached at
school that a foreign key can only point to the primary key of a table.
Perhaps you can try to do the following:

Create Table: CREATE TABLE `conn` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `wall_nr` int(6) unsigned NOT NULL default '0',
  `hub_switch` varchar(20) NOT NULL default '',
  `comp_name` varchar(50) NOT NULL default '',
  `name_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`name_id`),
  KEY `id` (`id`)
) TYPE=InnoDB


CREATE TABLE `ip_name_tbl` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `comp_loc` smallint(5) unsigned NOT NULL default '0',
  `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
  `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
  `IP` varchar(15) default NULL,
  `MAC` varchar(17) NOT NULL default '',
  `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
  `name_id` int(11) NOT NULL default '0',
  `comments` text,
  PRIMARY KEY  (`name_id`),
  FOREIGN KEY (name_id) REFERENCES conn ON DELETE CASCADES
  KEY `id` (`id`)
) TYPE=InnoDB;

Notice the foreign key already in the table definition, and off course
creating table `conn` before the other one. If this doesn't work, try
rewriting your foreign key constraint to:

ALTER TABLE ip_name_tbl
ADD CONSTRAINT FOREIGN KEY (name_id)
REFERENCES conn
ON DELETE CASCADE;

* without pointing to which column the key points, just the table.

Btw, why do you have an `id` field, set as NOT NULL and with an
auto_increment, with besides another field `name_id` set as primary key?

Greetzz,
Wouter

(being my first msg to this list, btw: hello everybody .. i'm wouter and new
to this list ;) hihi )

--
Alle door mij verzonden email is careware. Dit houdt in dat het alleen
herlezen en bewaard mag worden als je goed omgaat met al het leven op aarde
en daar buiten. Als je het hier niet mee eens bent dien je mijn mailtje
binnen 24 uur terug te sturen, met opgaaf van reden van onenigheid.

All email sent by me is careware. This means that it can only be reread and
kept if you are good for all the life here on earth and beyond. If you don't
agree to these terms, you should return this email in no more than 24 hours
stating the reason of disagreement.


-Oorspronkelijk bericht-
Van: Markus Lervik [mailto:[EMAIL PROTECTED]]
Verzonden: maandag 10 juni 2002 10:45
Aan: Kiss Dániel
CC: [EMAIL PROTECTED]
Onderwerp: Re: InnoDB foreign key constraints


On Monday 10 Jun 2002 11:17 am, you wrote:
 First of all the referenced key must be on PRIMARY KEY.

...which means my 'id' -field can't be a primary key, right?

 But I've seen in your table definition a quite strange thing. You have a
 UNIQUE and an ORDINARY key definition on the same field.
 Here:

UNIQUE KEY `name_id` (`name_id`), - THIS IS THE FIRST DEFINITION
UNIQUE KEY `comp_name` (`comp_name`),
KEY `conn_idx` (`name_id`) - AND THIS IS THE SECOND ONE

I've probably messed something up while fooling around with indexes and
trying
to get it to work. Now, I took the advices I got, but I still can't get it
to
work. I altered the table to make the 'id' -field an ordinary index, and
changed the name_id -field to a primary key, without luck. So now my
SHOW CREATE TABLE gives:

mysql show create table ip_name_tbl\G
*** 1. row ***
   Table: ip_name_tbl
Create Table: CREATE TABLE `ip_name_tbl` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `comp_loc` smallint(5) unsigned NOT NULL default '0',
  `comp_sub_loc` smallint(5) unsigned NOT NULL default '0',
  `ip_stat_dyn` enum('DHCP','STATIC') NOT NULL default 'DHCP',
  `IP` varchar(15) default NULL,
  `MAC` varchar(17) NOT NULL default '',
  `network` enum('Hallinto','Asiakas') NOT NULL default 'Hallinto',
  `name_id` int(11) NOT NULL default '0',
  `comments` text,
  PRIMARY KEY  (`name_id`),
  KEY `id` (`id`)
) TYPE=InnoDB

...and

mysql show create table conn\G
*** 1. row ***
   Table: conn
Create Table: CREATE TABLE `conn` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `wall_nr` int(6) unsigned NOT NULL default '0',
  `hub_switch` varchar(20) NOT NULL default '',
  `comp_name` varchar(50) NOT NULL default '',
  `name_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`name_id`),
  KEY `id` (`id`)
) TYPE=InnoDB


and, again:

mysql ALTER TABLE ip_name_tbl
- ADD CONSTRAINT FOREIGN KEY (name_id)
- REFERENCES conn (name_id)
- ON DELETE CASCADE;
ERROR 1005: Can't create table './koneet/#sql-355_4.frm' (errno: 150)

*sigh*

Cheers,
Markus

--
Markus Lervik
Linux-administrator
Vaasa City Library - Regional Library, Finland
[EMAIL PROTECTED]
+358-6-325 3589/+358-40-832 6709

-
Before posting, please check:
   http://www.mysql.com

Re: InnoDB Foreign Key Constraints

2002-05-13 Thread Heikki Tuuri

Daniel,

- Original Message -
From: Daniel Rand [EMAIL PROTECTED]
Newsgroups: mailing.database.mysql
Sent: Monday, May 13, 2002 5:24 PM
Subject: InnoDB Foreign Key Constraints


 Hi,

 Does anyone know if it's possible to set up a foreign key constraint where
 one table references the primary key of another table in a different
 database (both tables being of InnoDB type).

yes, you can use the databasename.tablename syntax:

heikki@hundin:~/mysql/client mysql test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 3.23.51-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql show create table aaa;
+---+---

---+
| Table | Create Table
   |
+---+---

---+
| aaa   | CREATE TABLE `aaa` (
  `a` int(11) NOT NULL default '0',
  `b` int(11) default NULL,
  PRIMARY KEY  (`a`),
  KEY `b` (`b`)
) TYPE=InnoDB |
+---+---

---+
1 row in set (0.01 sec)

mysql use test11
Database changed
mysql create table mmm (a int not null, b int, primary key (a), index (b),
fore
ign key (b) references test.aaa (a));
Query OK, 0 rows affected (0.00 sec)

mysql show create table mmm;
+---+---



+
| Table | Create Table

|
+---+---



+
| mmm   | CREATE TABLE `mmm` (
  `a` int(11) NOT NULL default '0',
  `b` int(11) default NULL,
  PRIMARY KEY  (`a`),
  KEY `b` (`b`),
  FOREIGN KEY (`b`) REFERENCES `test.aaa` (`a`)
) TYPE=InnoDB |
+---+---



+
1 row in set (0.00 sec)

mysql


 Thanks,

 DAN

Best regards,

Heikki Tuuri
Innobase Oy
---
InnoDB - transactions, hot backup, and foreign key support for MySQL
See http://www.innodb.com, download MySQL-Max from http://www.mysql.com




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php