<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Foreign Keys (Referential Integrity)</title>
        <description>Forum for Referential Integrity</description>
        <link>http://forums.mysql.com/list.php?135</link>
        <lastBuildDate>Wed, 22 May 2013 22:48:36 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?135,586656,586656#msg-586656</guid>
            <title>timestamp is not updated on foreign key update (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,586656,586656#msg-586656</link>
            <description><![CDATA[ I am using MYSQL 5.1.38 and I have following tables:<br />
<br />
create table table1 (  <br />
col1 varchar(50) primary key not null,  <br />
ts1 timestamp not null default current_timestamp on update current_timestamp  <br />
)engine=innodb;  <br />
<br />
create table table2 (<br />
col1 varchar(50) not null,<br />
ts2 timestamp not null default current_timestamp on update current_timestamp,  <br />
foreign key (col1) references table1 (col1) on update cascade on delete cascade  <br />
)engine=innodb;  <br />
<br />
<br />
When I update col1 in table1, the ts1 in table1 and col1 in table2 are updated but ts2 in table2 does not get updated.<br />
<br />
Here is the output:<br />
<br />
<br />
mysql&gt;   insert into table1 (col1) values ('test'); <br />
Query OK, 1 row affected (0.00 sec)<br />
<br />
mysql&gt;   insert into table2 (col1) values ('test');<br />
Query OK, 1 row affected (0.00 sec)<br />
<br />
mysql&gt; select * from table1;<br />
+------+---------------------+<br />
| col1 | ts1                 |<br />
+------+---------------------+<br />
| test | 2013-05-17 09:37:56 |<br />
+------+---------------------+<br />
1 row in set (0.00 sec)<br />
<br />
mysql&gt; select * from table2;<br />
+------+---------------------+<br />
| col1 | ts2                 |<br />
+------+---------------------+<br />
| test | 2013-05-17 09:38:03 |<br />
+------+---------------------+<br />
1 row in set (0.01 sec)<br />
<br />
mysql&gt; update table1 set col1='test1' where col1 = 'test';<br />
Query OK, 1 row affected (0.00 sec)<br />
Rows matched: 1  Changed: 1  Warnings: 0<br />
<br />
mysql&gt; select * from table1;<br />
+-------+---------------------+<br />
| col1  | ts1                 |<br />
+-------+---------------------+<br />
| test1 | 2013-05-17 09:44:28 |<br />
+-------+---------------------+<br />
1 row in set (0.00 sec)<br />
<br />
mysql&gt; select * from table2;<br />
+-------+---------------------+<br />
| col1  | ts2                 |<br />
+-------+---------------------+<br />
| test1 | 2013-05-17 09:38:03 |<br />
+-------+---------------------+<br />
1 row in set (0.00 sec)<br />
<br />
<br />
I would expect ts2 to be updated as well. Is this expected behaviour?]]></description>
            <dc:creator>Hemant Shah</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Sat, 18 May 2013 00:42:37 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,581520,581520#msg-581520</guid>
            <title>How know many to many relationship from information schema (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,581520,581520#msg-581520</link>
            <description><![CDATA[ how to know if a relationship is many to many type from INFORMATION SCHEMA]]></description>
            <dc:creator>Jorge prado</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Sat, 16 Mar 2013 06:34:01 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,578302,578302#msg-578302</guid>
            <title>error 1005 (hy000): can't create table reparto.simone (errno:105) (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,578302,578302#msg-578302</link>
            <description><![CDATA[ why i can't create the table reparto??? i use mysql 5.5 command line client<br />
<br />
<br />
Create table film (<br />
anno_produzione integer not null,<br />
titolo char not null,<br />
versione char,<br />
fascia_appartenenza char,<br />
primary key (anno_produzione, titolo),<br />
unique (titolo));<br />
<br />
create table abbonamento (<br />
cod integer primary key not null, <br />
Tipo char, <br />
Sconto integer, <br />
Data_reg datetime, <br />
Ncopie integer, <br />
Durata char,<br />
unique (cod));<br />
<br />
create table regione (<br />
nome char primary key not null,<br />
unique (nome));<br />
<br />
create table distributore (<br />
pi integer primary key not null);<br />
<br />
create table lingua (<br />
nome char primary key not null);<br />
<br />
<br />
<br />
<br />
create table provincia (<br />
nome char primary key not null,<br />
nome_regione char ,<br />
foreign key (nome_regione) references regione (nome),<br />
unique (nome));<br />
<br />
create table citta (<br />
nome char primary key not null,<br />
nome_provincia char,<br />
pi_distributore integer,<br />
foreign key (nome_provincia) references provincia (nome),<br />
foreign key (pi_distributore) references distributore (pi),<br />
unique (nome)); <br />
<br />
create table servicepoint (<br />
pi integer primary key not null,<br />
pi_distributore integer,<br />
nome_citta char,<br />
foreign key (pi_distributore) references distributore (pi),<br />
foreign key (nome_citta) references citta (nome),<br />
unique (pi));<br />
<br />
<br />
<br />
<br />
<br />
create table copiafisica (<br />
supporto char not null,<br />
titolo_film char not null,<br />
anno_produzione_film integer not null,<br />
primary key (supporto, titolo_film, anno_produzione_film),<br />
foreign key (titolo_film) references film (titolo),<br />
foreign key (anno_produzione_film) references film (anno_produzione));<br />
<br />
create table magazzino (<br />
via char not null,<br />
numero_civico integer not null,<br />
pi_servicepoint integer not null,<br />
nome_citta char,<br />
primary key (via, numero_civico, pi_servicepoint),<br />
foreign key (pi_servicepoint) references servicepoint (pi),<br />
foreign key (nome_citta) references citta (nome),<br />
unique (via, numero_civico));<br />
<br />
create table reparto (<br />
nome char primary key not null,<br />
numero_civico_magazzino integer,<br />
via_magazzino char,<br />
foreign key (numero_civico_magazzino) references magazzino (numero_civico),<br />
foreign key (via_magazzino) references magazzino (via));]]></description>
            <dc:creator>simone mancaruso</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 01 Feb 2013 13:38:33 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,578080,578080#msg-578080</guid>
            <title>Importing dump from relational db while maintaining referential integrity (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,578080,578080#msg-578080</link>
            <description><![CDATA[ Hi<br />
<br />
For the sake of this example. let's say I have a central server that contains 1000s of rows spread over several tables. They're linked together with foreign keys, that is, a relational database (InnoDB). This is database A.<br />
<br />
I have several client databases from which I generate partial dumps that needs to be merged into database A. The client databases have the same schemata as database A.<br />
<br />
While maintaining referential integrity, how do I import the client dumps into database A? If, let's say, I dump the contents of client databases, the keys and foreign keys are &quot;hardcoded&quot; into the dump-file. If I were to import this into database A, MySQL would just throw &quot;Duplicate entry 'x' for key 'primary'&quot;. If I were to exclude id's from the dump-file, referential integrity would not be maintained between the different tables. <br />
<br />
Is there some ingenious way of doing this that I'm missing?<br />
<br />
Thanks in advance!]]></description>
            <dc:creator>Fredrik Krokstad</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 28 Jan 2013 17:03:03 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,575416,575416#msg-575416</guid>
            <title>Normalise and uniqueness of a dataset where the combination of three columns is unique and one column is a many to many relationship (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,575416,575416#msg-575416</link>
            <description><![CDATA[ I am faced with a unique requirement and I cannot figure out the elegant way of implementing this without a trigger, but that sounds like a workaround rather than proper design. <br />
<br />
Lets say we have this non normalised dataset<br />
<br />
Object ID (PK)	Server Name	domain		role	priority	<br />
1	server1.domain.name	ALL		1	P	<br />
2	server2.domain.name	1,2,3		2	B	<br />
3	server3.domain.name	1,2,3,4,5	1	S	<br />
4	server4.domain.name	ALL		3	S	<br />
5	server5.domain.name	3,4,5		2	S	<br />
6	server6.domain.name	ALL		2	B	<br />
7	server7.domain.name	1,2,3,4,5	1	S	DUP<br />
8	server8.domain.name	ALL		3	S	DUP<br />
<br />
Above DUP means duplicate as in this breaks the following constraints<br />
<br />
-combination of domain, role and priority is unique (see the red lines break this uniqueness)<br />
-domain column is a list of IDs or ALL is assumed (i implement this with a many to many relationship  so if there is none ALL is assumed )<br />
<br />
What design would you apply (if you could provide create statements would be great but not necessary) to have the above relations and constraints normalised?<br />
<br />
Thanks in advance for replying<br />
<br />
The text included in this forum might not show the raw data well. Please check this image to clarify it<br />
<a href="http://bizmate.dreamhosters.com/normalise_unique_multipleFields.png"  rel="nofollow">http://bizmate.dreamhosters.com/normalise_unique_multipleFields.png</a>]]></description>
            <dc:creator>diego gullo</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Thu, 06 Dec 2012 11:42:20 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,573276,573276#msg-573276</guid>
            <title>error in foreign key constraint definition (2 replies)</title>
            <link>http://forums.mysql.com/read.php?135,573276,573276#msg-573276</link>
            <description><![CDATA[ Hi everybody,<br />
<br />
I have a problem creating a foreign key constraint between two tables.<br />
<br />
Here is the first table:<br />
<br />
CREATE TABLE `agews_rifiuti_cer` (<br />
  `id_cer` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  `agews_id` int(10) unsigned DEFAULT '0',<br />
  `livello` tinyint(4) DEFAULT '1',<br />
  `codice` varchar(10) DEFAULT NULL,<br />
  `descrizione` varchar(255) DEFAULT NULL,<br />
  `note` text,<br />
  `flag_pericoloso` tinyint(1) DEFAULT '0',<br />
  `id_cliente` int(10) unsigned DEFAULT '1',<br />
  `flag_modificato` char(1) DEFAULT 'N',<br />
  PRIMARY KEY (`id_cer`),<br />
  KEY `fk_id_cliente_agews_sgs_codici_cer` (`id_cliente`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;<br />
<br />
And here is the second one:<br />
<br />
CREATE TABLE `lin_98_47_rifiuti` (<br />
  `id_rifiuto` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  `id_azienda` int(10) unsigned NOT NULL DEFAULT '1',<br />
  `id_sede` int(10) unsigned NOT NULL DEFAULT '1',<br />
  `revisione_documento` int(10) unsigned NOT NULL DEFAULT '0',<br />
  `rifiuto` varchar(255) DEFAULT NULL,<br />
  `codice_cer` varchar(10) DEFAULT NULL,<br />
  `nome_interno` varchar(255) DEFAULT NULL,<br />
  `descrizione` text,<br />
  `materie_prime` text,<br />
  `contenitore` text,<br />
  `deposito` text,<br />
  `data_ultima_analisi` date DEFAULT NULL,<br />
  `stato_fisico` enum('Solido pulverulento','Solido non pulverulento','Fangoso palabile','Liquido') DEFAULT 'Solido non pulverulento',<br />
  `quantita` float(9,1) DEFAULT '0.0',<br />
  `unita_misura` enum('Kg','l','mc') DEFAULT 'Kg',<br />
  `id_pericolo` int(10) unsigned DEFAULT NULL,<br />
  `destino` enum('Recupero','Smaltimento') DEFAULT NULL,<br />
  `id_recupero` int(10) unsigned DEFAULT NULL,<br />
  `id_smaltimento` int(10) unsigned DEFAULT NULL,<br />
  `id_cer` int(10) unsigned DEFAULT NULL,<br />
  `immagine` varchar(255) DEFAULT NULL,<br />
  `image_type` varchar(20) DEFAULT NULL,<br />
  `image_content` mediumblob,<br />
  `image_size_x` smallint(5) unsigned DEFAULT '0',<br />
  `image_size_y` smallint(5) unsigned DEFAULT '0',<br />
  `flag_storico` tinyint(1) DEFAULT '0',<br />
  `id_responsabile` int(10) unsigned DEFAULT '0',<br />
  `nome_responsabile` varchar(255) DEFAULT '0',<br />
  `id_ultima_modifica` int(10) unsigned DEFAULT '0',<br />
  `create_log` tinyint(1) DEFAULT '1',<br />
  PRIMARY KEY (`id_rifiuto`,`id_azienda`,`id_sede`,`revisione_documento`),<br />
  KEY `fk_main_lin_98_47_rifiuti` (`id_azienda`,`id_sede`,`revisione_documento`),<br />
  KEY `fk_id_responsabile_lin_98_47_rifiuti` (`id_responsabile`,`id_azienda`,`id_sede`,`revisione_documento`,`nome_responsabile`),<br />
  KEY `fk_id_pericolo_lin_98_47_rifiuti` (`id_pericolo`),<br />
  KEY `fk_id_recupero_lin_98_47_rifiuti` (`id_recupero`),<br />
  KEY `fk_id_smaltimento_lin_98_47_rifiuti` (`id_smaltimento`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;<br />
<br />
The problem happens the I try to do this:<br />
<br />
ALTER TABLE lin_98_47_rifiuti ADD CONSTRAINT fk_id_cer_lin_98_47_rifiuti FOREIGN KEY (id_cer) REFERENCES agews_rifiuti_cer(id_cer) ON UPDATE CASCADE ON DELETE CASCADE;<br />
<br />
And I get this error:<br />
<br />
#1005 - Can't create table 'db_626suite.#sql-71c_13d5' (errno: 150)<br />
<br />
While the command SHOW INNODB STATUS says:<br />
<br />
Error in foreign key constraint of table db_626suite/#sql-71c_13d5:<br />
 FOREIGN KEY (id_cer) REFERENCES agews_rifiuti_cer(id_cer) ON UPDATE CASCADE ON DELETE CASCADE:<br />
Cannot resolve column name close to:<br />
) ON UPDATE CASCADE ON DELETE CASCADE<br />
<br />
But the syntax and fields definitions seem correct to me. What am I doing wrong?]]></description>
            <dc:creator>Matteo Tassinari</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 09 Nov 2012 12:34:33 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,571584,571584#msg-571584</guid>
            <title>foreing key and Partitioned table (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,571584,571584#msg-571584</link>
            <description><![CDATA[ I am trying to apply pk-fk to a partitioned table and get an error. <br />
<br />
Error Code: 1506: Foreign key clause is not yet supported in conjunction with partitioning<br />
<br />
Mysql 5.5.12, engine innodb<br />
<br />
Is it true that MySQL is not able to do this? How can one have a descent DB?]]></description>
            <dc:creator>Pieter Huiberts</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 19 Oct 2012 17:27:32 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,564643,564643#msg-564643</guid>
            <title>Foreign Key on part of a unique index (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,564643,564643#msg-564643</link>
            <description><![CDATA[ I got the following tables:<br />
<br />
A: key(id) data ...<br />
B: key(id,language) data ...<br />
<br />
The id from A should link to the id of B. That works fine until I try to delete a entry in B. Because the key consists of id AND language the table could look like this:<br />
<br />
(1, DE) Tür<br />
(1, EN) Door<br />
(1, ME) Ding<br />
<br />
I want to delete (1, ME), but the foreign key fails (id is in use in table A!)<br />
<br />
The FK should only fail if the last entry with ID isdelete (so there is no entry for (id) in any language...) How can I solve this?]]></description>
            <dc:creator>Mr Xax</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 10 Aug 2012 18:41:09 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,562777,562777#msg-562777</guid>
            <title>Can a single foreign key point to multiple primary keys? (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,562777,562777#msg-562777</link>
            <description><![CDATA[ Hi all;<br />
<br />
I have a case where the DB is set up with (simplifying) a table User and a table SuperUser. Both have a column Id. Every SuperUser row has a row in the User table with the same Id value (not my design!!!). The SUperUser table does not pull common info from the User table, it duplicates it.<br />
<br />
Can/should any foreign key that points to User.Id also have a FK:PK relationship with SuperUser.Id? My take on this is it is at a minimum a very bad idea and that many (most?) DBs can't enforce this relationship/<br />
<br />
Am I off base here?]]></description>
            <dc:creator>David Thielen</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Wed, 25 Jul 2012 14:14:10 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,562136,562136#msg-562136</guid>
            <title>change a PK value and all it's FK value (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,562136,562136#msg-562136</link>
            <description><![CDATA[ i have a table1 where each row has a PK, this PK is used in other tables (table2 to table 32) as an FK.<br />
<br />
I want to update table1 row1 PK from e.g. 2 to 3 - I also then want to update the value where it's used as an FK in other tables?<br />
<br />
I have 32 other tables to update that reference the PK - how can I do it quickly?<br />
<br />
the command i have got so far UPDATE table1 set id=2 where id=3; I have come across the command UPDATE CASCADE but can't get that to work<br />
<br />
thanks]]></description>
            <dc:creator>DIL DIL</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jul 2012 17:47:36 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,561985,561985#msg-561985</guid>
            <title>I can't point foreign key to date field type (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,561985,561985#msg-561985</link>
            <description><![CDATA[ I have 2 table. It called mEmpl and mOrder.<br />
<br />
mEmpl have 9 field, there are: IDEmployee (int), ShortName (varchar), Name (varchar), DBegin (date primary key), DEnd (date primary key), Directory (varchar), Mode (varchar primary key), PartTime (varchar), IDJob (int).<br />
<br />
mOrder have 11 field, there are: IDOrder (int), NrOrder (int), OrderDesc (varchar), IDOwner (int), Budget (float), DBegin (date), DEnd (date), Mode (varchar), ArtCost (int), BaseRate (int), BaseItem (int).<br />
<br />
When I try to add foreign key at mOrder(DBegin, DEnd, and Mode) which references by mEmpl, it always raise error message: ERROR 1005 (HY000): Can't create table 'spezet.#sql-4d4_1' (errno: 150)<br />
<br />
However, if I just add foreign key to DBegin only like this: ALTER TABLE mOrder ADD FOREIGN KEY (DBegin) REFERENCES mEmpl(DBegin);<br />
<br />
There's not raising any error! The DBegin is successfully pointing to mEmpl.DBegin primary key.<br />
<br />
Anyone can describe to me whats wrong here? Whether MySQL indeed can't point to 2 date field at once? Thanks before for your replies..]]></description>
            <dc:creator>Andro Meda</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jul 2012 17:44:15 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,560089,560089#msg-560089</guid>
            <title>Foreign keys and indexes autocreation issue (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,560089,560089#msg-560089</link>
            <description><![CDATA[ I am investigating an issue regarding foreign key and (necessary) indexes creation.<br />
At mysql documentation i have read the comment:<br />
&quot;InnoDB enables you to add a new foreign key constraint to a table by using ALTER TABLE:<br />
<br />
ALTER TABLE tbl_name<br />
    ADD [CONSTRAINT [symbol]] FOREIGN KEY<br />
    [index_name] (index_col_name, ...)<br />
    REFERENCES tbl_name (index_col_name,...)<br />
    [ON DELETE reference_option]<br />
    [ON UPDATE reference_option]<br />
The foreign key can be self referential (referring to the same table). When you add a foreign key constraint to a table using ALTER TABLE, remember to create the required indexes first.&quot;<br />
<br />
So, in order to identify the different treatment between create table and alter table syntax i have created these two simple tables:<br />
<br />
CREATE TABLE `myDomain1` (<br />
  `UUIDKey` char(32) default '',<br />
  `AttributeValue` varchar(255) NOT NULL unique,<br />
  PRIMARY KEY  (`UUIDKey`)<br />
) ENGINE=InnoDB;<br />
<br />
CREATE TABLE `myDomain2` (<br />
  `UUIDKey` char(32) default '',<br />
  `Attribute` varchar(255) NOT NULL,<br />
  PRIMARY KEY  (`UUIDKey`),<br />
  constraint `FkmyDomain1AttributeValue` FOREIGN KEY (`Attribute`) <br />
        REFERENCES `myDomain1` (`AttributeValue`) ON DELETE CASCADE<br />
);<br />
<br />
The creation of myDomain2 was successfull and resulted at the creation of FkmyDomain1AttributeValue index. <br />
<br />
However, triggering the sql command<br />
CREATE INDEX `FkmyDomain1AttributeValue` on `myDomain2`(`Attribute`) ; <br />
also succeeds, that leads to the assumption that no index was found?<br />
<br />
As a next step, i have used the following syntax for myDomain2 creation:<br />
<br />
CREATE TABLE `myDomain2` (<br />
  `UUIDKey` char(32) default '',<br />
  `Attribute` varchar(255) default NULL,<br />
  PRIMARY KEY  (`UUIDKey`)<br />
) ENGINE=InnoDB;<br />
<br />
alter table `myDomain2` <br />
add constraint `FkmyDomain1AttributeValue` <br />
        FOREIGN KEY (`Attribute`) <br />
        REFERENCES `myDomain1` (`AttributeValue`) ON DELETE CASCADE;<br />
<br />
Again issuing the <br />
CREATE INDEX `FkmyDomain1AttributeValue` on `myDomain2`(`Attribute`) ; <br />
succeeded.<br />
<br />
So, two questions arise:<br />
1) What is the meaning of the comment at the documentation? (When you add a foreign key constraint to a table using ALTER TABLE, remember to create the required indexes first.)<br />
2) Are explicit calls to index creation needed? This would have a big impact on performance i guess...<br />
<br />
Another important remark in terms of this issue is that when experimenting with MySQL v5.5 the test has different behaviour; the create index sql command fails with the following:	<br />
create index `FkmyDomain1AttributeValue` on `myDomain2`(`Attribute`)	Error Code: 1280. Incorrect index name 'FkmyDomain1AttributeValue'<br />
<br />
in both cases (create table/alter table syntax).<br />
<br />
So, was that a problem of MySql v5.0 which has been fixed in newer versions? <br />
<br />
Could anybody please comment on this?]]></description>
            <dc:creator>Dimitrios Iosifidis</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jul 2012 17:54:36 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,558895,558895#msg-558895</guid>
            <title>relationship tables (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,558895,558895#msg-558895</link>
            <description><![CDATA[ Hi everyone,<br />
<br />
Im in need of help to understand how can I structure my database with multiple tables. <br />
<br />
I have a database and here are the tables I created<br />
<br />
1-players<br />
2-testings<br />
3-position<br />
4-stats<br />
<br />
My main table will be the player table and I want all the other table to be link to that one. <br />
<br />
lets say I create a player on table one, I want to link that table to testing, position and stats tables. Because without the player there are no testing, no position and no stats. <br />
<br />
<br />
I dont know if my question is clear? If it is how do I create this?]]></description>
            <dc:creator>mvpfootball consulting</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jul 2012 17:56:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,536181,536181#msg-536181</guid>
            <title>Linking table for rows in the same table (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,536181,536181#msg-536181</link>
            <description><![CDATA[ Hello, I apologize if this is a very newbie question. I've tried to find answers here and on Google and I may just be ignorant of how to frame the search.<br />
<br />
I need to create a linking table that identifies a bi-lateral relationship between entities in the same table. As an example, consider a table of users where I want to indicate a partnership relationship between user 100 and user 1. <br />
<br />
I've already realized I need a composite key, or I risk having this happen:<br />
Id     User1     User2    <br />
1      1         100       <br />
2      1         100       <br />
<br />
So, two rows with two different primary keys relating the same data.<br />
<br />
However, even if I use a primary key of user1+user2, how do I avoid this:<br />
User1      User2<br />
1          100       <br />
100        1<br />
<br />
Any theoretical or practical advice would be much appreciated. <br />
<br />
Thank you in advance.]]></description>
            <dc:creator>D Harrison</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jul 2012 18:05:01 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,528651,528651#msg-528651</guid>
            <title>Zero Instead of Null Vs Two Tables. (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,528651,528651#msg-528651</link>
            <description><![CDATA[ I'm working on refactoring a database(s) we have, it involves over 100 separate databases with 30 plus tables in each database.  Each table is exactly the same schema (Code VARCHAR(10), Description (VARCHAR(75)).  If I add a key (ID2) to indicate which of the thirty odd tables a one of these records belonged too, I get get it down to one table per database.  I can then add a key (ID1) to indicate which database the tables came from and take it all down to one table (not counting the database name / table name reference tables).<br />
<br />
So my schema will end up beign (ID1 Int, ID2 Int, Code VARCHAR(10), Description VARCHAR(10).  I have a question because a number of the Code tables are identical in each database, and they will not ever vary.<br />
<br />
My initial thought was to have two tables.  One wouldn't have ID1 on it, and would be used to hold those code tables that didn't vary from database to database and I'd have the table with ID1 that would hold those that did.  I am, however, not very keen on having to maintain to tables that look so similar.  How bad would it be to add to the database names table a &quot;0&quot; key value then using 0 as the ID1 for all code tables that didn't vary from database to database.<br />
<br />
Thanks<br />
<br />
    - Bryce]]></description>
            <dc:creator>Bryce Byrd</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 27 Apr 2012 19:23:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,527036,527036#msg-527036</guid>
            <title>errors with foreign keys (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,527036,527036#msg-527036</link>
            <description><![CDATA[ Hello all,<br />
<br />
I keep receiving these errors when attempting to create a few tables. I cannot for the life me figure out what I am missing.<br />
<br />
ERROR 1005 (HY000): Can't create table './user/EMPLOYEE.frm' (errno: 150)<br />
ERROR 1005 (HY000): Can't create table './user/VEHICLE.frm' (errno: 150)<br />
ERROR 1005 (HY000): Can't create table './user/EQUIPMENT.frm' (errno: 150)<br />
<br />
<br />
CREATE TABLE DIR_INTELLIGENCE<br />
(DIR_I_DEPT DECIMAL(4,0) PRIMARY KEY,<br />
DIR_I_BUDGET DECIMAL(7,2),<br />
DIR_I_CREDITLIMIT DECIMAL(7,2));<br />
CREATE TABLE NATIONAL_C_SVC<br />
(NAT_C_DEPT DECIMAL(4,0) PRIMARY KEY,<br />
NAT_C_BUDGET DECIMAL(7,2) NOT NULL,<br />
NAT_C_CREDITLIMIT DECIMAL(7,2));<br />
CREATE TABLE DIR_SCIENCE_TECH<br />
(DIR_S_T_DEPT DECIMAL(4,0) PRIMARY KEY,<br />
DIR_S_T_BUDGET DECIMAL(7,2),<br />
DIR_S_T_CREDITLIMIT DECIMAL(7,2));<br />
CREATE TABLE DIR_SUPPORT<br />
(DIR_S_DEPT DECIMAL(4,0) PRIMARY KEY,<br />
DIR_S_BUDGET DECIMAL(7,2),<br />
DIR_S_CREDITLIMIT DECIMAL(7,2));<br />
CREATE TABLE EMPLOYEE<br />
(DIR_S_DEPT DECIMAL(4,0),<br />
NAT_C_DEPT DECIMAL(4,0),<br />
DIR_I_DEPT DECIMAL(4,0),<br />
DIR_S_T_DEPT DECIMAL(4,0),<br />
EMP_LNAME CHAR(15),<br />
EMP_FNAME CHAR(15),<br />
EMP_POSITION CHAR(15),<br />
EMP_ADDR CHAR(15),<br />
EMP_CITY CHAR(20),<br />
EMP_ZIP DECIMAL(5,0),<br />
EMP_PHONE DECIMAL(10,0),<br />
EMP_EQUIP CHAR(15),<br />
EMP_VEHICLE CHAR(3),<br />
FOREIGN KEY (DIR_S_DEPT) REFERENCES DIR_SUPPORT (DIR_S_DEPT),<br />
FOREIGN KEY (NAT_C_DEPT) REFERENCES NATIONAL_CLANDESTINE_SVC (NAT_C_DEPT),<br />
FOREIGN KEY (DIR_I_DEPT) REFERENCES DIR_INTELLIGENCE (DIR_I_DEPT),<br />
FOREIGN KEY (DIR_S_T_DEPT) REFERENCES DIR_SCIENCE_TECH (DIR_S_T_DEPT),<br />
PRIMARY KEY (EMP_LNAME, EMP_FNAME, DIR_S_DEPT, NAT_C_DEPT, DIR_I_DEPT, DIR_S_T_DEPT) );<br />
CREATE TABLE VEHICLE<br />
(DIR_S_DEPT DECIMAL(4,0),<br />
NAT_C_DEPT DECIMAL(4,0),<br />
DIR_I_DEPT DECIMAL(4,0),<br />
DIR_S_T_DEPT DECIMAL(4,0),<br />
EMP_LNAME CHAR(15),<br />
EMP_FNAME CHAR(15),<br />
VEH_TYPE CHAR(4),<br />
VEH_PLATE CHAR(8),<br />
VEH_VIN DECIMAL(20,0),<br />
VEH_MODEL CHAR(10),<br />
VEH_MANU CHAR(10),<br />
FOREIGN KEY (DIR_S_DEPT) REFERENCES DIR_SUPPORT (DIR_S_DEPT),<br />
FOREIGN KEY (NAT_C_DEPT) REFERENCES NATIONAL_CLANDESTINE_SVC (NAT_C_DEPT),<br />
FOREIGN KEY (DIR_I_DEPT) REFERENCES DIR_INTELLIGENCE (DIR_I_DEPT),<br />
FOREIGN KEY (DIR_S_T_DEPT) REFERENCES DIR_SCIENCE_TECH (DIR_S_T_DEPT),<br />
FOREIGN KEY (EMP_LNAME) REFERENCES EMPLOYEE (EMP_LNAME),<br />
FOREIGN KEY (EMP_FNAME) REFERENCES EMPLOYEE (EMP_FNAME),<br />
PRIMARY KEY (DIR_S_DEPT, NAT_C_DEPT, DIR_I_DEPT, DIR_S_T_DEPT, VEH_TYPE) );<br />
CREATE TABLE EQUIPMENT<br />
(DIR_S_DEPT DECIMAL(4,0),<br />
NAT_C_DEPT DECIMAL(4,0),<br />
DIR_I_DEPT DECIMAL(4,0),<br />
DIR_S_T_DEPT DECIMAL(4,0),<br />
EMP_LNAME CHAR(15),<br />
EMP_FNAME CHAR(15),<br />
EQUIP_TYPE CHAR(20),<br />
EQUIP_ISSUED_ON DATE,<br />
EQUIP_RETURN_ON DATE,<br />
EQUIP_OVERDUE CHAR(3),<br />
EMP_EQUIP CHAR(3),<br />
FOREIGN KEY (DIR_S_DEPT) REFERENCES DIR_SUPPORT (DIR_S_DEPT),<br />
FOREIGN KEY (NAT_C_DEPT) REFERENCES NATIONAL_CLANDESTINE_SVC (NAT_C_DEPT),<br />
FOREIGN KEY (DIR_I_DEPT) REFERENCES DIR_INTELLIGENCE (DIR_I_DEPT),<br />
FOREIGN KEY (DIR_S_T_DEPT) REFERENCES DIR_SCIENCE_TECH (DIR_S_T_DEPT),<br />
FOREIGN KEY (EMP_LNAME) REFERENCES EMPLOYEE (EMP_LNAME),<br />
FOREIGN KEY (EMP_FNAME) REFERENCES EMPLOYEE (EMP_FNAME),<br />
PRIMARY KEY (DIR_S_DEPT, NAT_C_DEPT, DIR_I_DEPT, DIR_S_T_DEPT, EQUIP_TYPE) );]]></description>
            <dc:creator>Crispy X</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Sat, 28 Apr 2012 08:20:22 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,524255,524255#msg-524255</guid>
            <title>Sql execution error #1005 .response from the database (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,524255,524255#msg-524255</link>
            <description><![CDATA[ Hello,<br />
<br />
I am getting &quot;SQL execution error #1005.Response from the database&quot; error no 121 error when i execute the below sql scripts. <br />
<br />
The foreign key named &quot;fk_category_id&quot; exists in both subcategory table and property table .The error is getting resolved when i name the foreign keys in these 2 tables differently .<br />
<br />
So my question is should the foreign key names across tables be unique in mysql ?? <br />
<br />
is there any other reason that this error can occur?? <br />
<br />
CREATE  TABLE IF NOT EXISTS `sampledb`.`category` (<br />
  `category_id` INT NOT NULL ,<br />
  PRIMARY KEY (`category_id`) )<br />
<br />
CREATE  TABLE IF NOT EXISTS `sampledb`.`subcategory` (<br />
  `subcategory_id` INT NOT NULL ,<br />
  `category_id` INT NULL ,<br />
  PRIMARY KEY (`subcategory_id`) ,<br />
   CONSTRAINT `fk_category_id`<br />
    FOREIGN KEY (`category_id` )<br />
    REFERENCES `realtydb`.`category` (`category_id` ))<br />
<br />
<br />
CREATE  TABLE IF NOT EXISTS `sampledb`.`property` (<br />
  `property_id` INT NOT NULL ,<br />
  `category_id` INT NULL ,<br />
  PRIMARY KEY (`property_id`) ,<br />
   CONSTRAINT `fk_category_id`<br />
    FOREIGN KEY (`category_id` )<br />
    REFERENCES `realtydb`.`category` (`category_id` ))]]></description>
            <dc:creator>giri giri</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Sun, 08 Apr 2012 21:19:31 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,521514,521514#msg-521514</guid>
            <title>&quot;Indirect&quot; foreign key (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,521514,521514#msg-521514</link>
            <description><![CDATA[ This is for a game.<br />
<br />
Simply put, there are several races, each consisting of several subraces. Some careers can only be pursued by character of the approriate race, but the character table contains only the subrace, as to avoid redundancy.<br />
<br />
<blockquote class="bbcode"><div><small>Quote<br/></small><strong>Not actual code, just to illustrate the setup</strong><br/>
<br />
TABLE `race` (<br />
   `race_id` INT,<br />
   PRIMARY KEY (`race_id`)<br />
)<br />
<br />
TABLE `subrace` (<br />
   `subrace_id` INT,<br />
   `race_id` INT,<br />
   PRIMARY KEY (`subrace_id`),<br />
   FOREIGN KEY (`race_id`) REFERENCES `race`(`race_id`)<br />
)<br />
<br />
TABLE `career` (<br />
   `career_id` INT,<br />
   PRIMARY KEY (`career_id`)<br />
)<br />
<br />
TABLE `career_eligible_race` (<br />
   `career_id` INT,<br />
   `race_id` INT,<br />
   PRIMARY KEY (`career_id`, `race_id`),<br />
   FOREIGN KEY (`career_id`) REFERENCES `career`(`career_id`),<br />
   FOREIGN KEY (`race_id`) REFERENCES `race`(`race_id`)<br />
)<br />
<br />
TABLE `character` (<br />
   `character_id` INT,<br />
   `subrace_id` INT,<br />
   `career_id` INT,<br />
   PRIMARY KEY (`character_id`),<br />
   FOREIGN KEY (`subrace_id`) REFERENCES `subrace`(`subrace_id`),<br />
   FOREIGN KEY (`career_id`) REFERENCES `career`(`career_id`)<br />
)</div></blockquote>
<br />
Now, I want to make a constraint that makes sure that a character with a given subrace is eligible to pursue his career.<br />
<br />
The only option I could think of was adding a race attribute to the character table, and constrain it with a composite foreign key of both race and subrace, referencing the subrace table. But again, redundancy.]]></description>
            <dc:creator>Ivar Kråbøl</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 23 Mar 2012 22:41:18 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,515216,515216#msg-515216</guid>
            <title>como puedo hacer que un tabla se relacione dos veces con otra tabla. (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,515216,515216#msg-515216</link>
            <description><![CDATA[ bueno mi dua es que tengo tabla1 con los campos idtabla1 , nombre y tengo la tabla2 con los campos idtabla2, idtabla1_1,idtabla1_2,nombre. lo que quiero es relacionar los campos idtabla1_1,idtabla1_2 de la tabla2 con el campo idtabla1 de la tabla1.<br />
 <br />
mi codigo es el siguiedrop database if exists prueba; <br />
<br />
create database prueba; <br />
<br />
use prueba; <br />
<br />
create table tabla1 <br />
( <br />
idtabla1 integer primary key, <br />
nombre varchar(50) <br />
)ENGINE=InnoDB DEFAULT CHARSET=utf8; <br />
<br />
insert into tabla1 values(1,'oscar'); <br />
insert into tabla1 values(2,'Carlos'); <br />
<br />
create table tabla2 <br />
( <br />
idtabla2 integer , <br />
idtabla1_1 integer , <br />
idtabla1_2 integer, <br />
nombre varchar (50), <br />
primary key(idtabla2,idtabla1_1,idtabla1_2), <br />
foreign key(idtabla1_1,idtabla1_2) <br />
references tabla1(idtabla1) <br />
)ENGINE=InnoDB DEFAULT CHARSET=utf8; <br />
<br />
<br />
insert into tabla2 values (1,1,2,'oskitar'); <br />
<br />
<br />
y me bota error 1239 <br />
<br />
por favor ayudame resien estoy empesando con mysql <br />
<br />
la imegen del modelo de la tabla <br />
<br />
<a href="http://img716.imageshack.us/img716/246/relan.png"  rel="nofollow">http://img716.imageshack.us/img716/246/relan.png</a>]]></description>
            <dc:creator>Oscar Ordoñez Mego</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Tue, 14 Feb 2012 02:32:56 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,511419,511419#msg-511419</guid>
            <title>dropping a foreign key (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,511419,511419#msg-511419</link>
            <description><![CDATA[ pls i need urgent help on this one.<br />
i creeted a table using InnoDb as my engine since MyIsam is not giving me what I want.<br />
here is the create table statements;<br />
create table staff<br />
(<br />
 staff_id int,<br />
 staff_name varchar(10),<br />
 primary key (staff_id)<br />
 ) engine = InnoDB;<br />
<br />
create table student<br />
( <br />
 reg_no int,<br />
 name varchar(10),<br />
 staff_adviser int,<br />
 primary key(reg_no),<br />
 constraint fk_student foreign key(staff_adviser) references staff(staff_id) on update cascade on delete cascade) engine = InnoDB;<br />
<br />
<br />
the table creation was successful and all insertions and referential actions were also successful. but when I tried to drop the foreign key I used the statement<br />
<br />
alter table student drop constraint fk_student;<br />
and i got this error:<br />
error 1064(42000) you hve an error in your sql syntax; check the manual that correspond to your mysql server versio for the right syntax to use near 'constraint fk_student' at line 1.<br />
<br />
then I tried to use this sytax;<br />
alter table student drop fk_student;<br />
and I got this error;<br />
erroe 1091 (4200) :can't drop 'fk_student' check that the column/key exists.<br />
<br />
then I used this;<br />
alter table student drop foreign key;<br />
and i got the error:<br />
error 1005 (HY000): can't create table 'school.#sql-13fc_1 (errno150)<br />
<br />
but when I used this sytax;<br />
alter table student drop foreign key fk_student;<br />
it say query ok. <br />
and when desscribed the table i.e describe student:<br />
i still saw the foreign key there.]]></description>
            <dc:creator>adams johnson</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 23 Jan 2012 10:20:58 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,508679,508679#msg-508679</guid>
            <title>Deleting Records (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,508679,508679#msg-508679</link>
            <description><![CDATA[ Hi ,<br />
<br />
I have tables which hold foreign key constraint to maintain referentialintegerity among two tables. I have defined On Delete Cascade and On Update Cascade in my table defination on the key. <br />
Now when I am deleting a record from the parent table, the record is getting deleted without any change made to the child table, thus violating the integrity of the system. <br />
This is what I am facing on mysql5.1.x<br />
Is there any server configuration required to remove this issue? <br />
What is the version of mysql which has overcome this issue??<br />
<br />
Thanks in advance.]]></description>
            <dc:creator>Sushmita Mishra</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Tue, 24 Jan 2012 09:04:11 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,508046,508046#msg-508046</guid>
            <title>dropping foreign keys (5 replies)</title>
            <link>http://forums.mysql.com/read.php?135,508046,508046#msg-508046</link>
            <description><![CDATA[ i created a table and added a foreign key. but the problem is that i cant drop the foreign key. whenever I try it says query o.k but when i check the table, the foreign key is still there. here are the two tables;<br />
create table students(reg_no int, name varchar(10), staff_adv int, primary key (reg_no)) engine = InnoDB;<br />
create table staff (staff_id int, name varchar(10), student_with int, primary key (student_with)) engine = InnoDB;<br />
then i added the foreign key thus;<br />
alter table staff add constraint fk_staff foreign key(student_with) references students on update cascade on delete set null;<br />
but when i try to drop the foreign key like this;<br />
alter table staff drop foreign key fk_staff;<br />
it says query ok, 2 rows affected &lt;0.09sec&gt;<br />
but if I describe the table i still see the foreign key. pls what should I do?]]></description>
            <dc:creator>adams johnson</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Wed, 11 Jan 2012 09:55:12 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,477895,477895#msg-477895</guid>
            <title>What is the best way to remove all Foreign Keys  for a refactoring (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,477895,477895#msg-477895</link>
            <description><![CDATA[ We are currently working on a major refactoring of the database and as part of the process, I need to remove all of the existing Foreign Key Contraints and create new ones.<br />
<br />
Right now I have the following code to find and remove the constraints:<br />
<br />
    $query = &quot;<br />
        SELECT DISTINCT TABLE_NAME, CONSTRAINT_NAME<br />
        FROM INFORMATION_SCHEMA.key_column_usage<br />
        WHERE CONSTRAINT_SCHEMA = 'optimus'<br />
        AND REFERENCED_TABLE_NAME IS NOT NULL<br />
    &quot;;<br />
<br />
    $result = $this-&gt;_query($query);<br />
<br />
    foreach ($result as $row) {<br />
        echo &quot;\tDropping {$row-&gt;TABLE_NAME}.{$row-&gt;CONSTRAINT_NAME}\n&quot;;<br />
        $this-&gt;_query(&quot;<br />
            ALTER TABLE `{$row-&gt;TABLE_NAME}`<br />
            DROP FOREIGN KEY `{$row-&gt;CONSTRAINT_NAME}`;<br />
        &quot;);<br />
    }<br />
<br />
But this creates two problems I have not been able to solve:<br />
<br />
a) All of the tables still have the original KEYS that were created for the foreign key contraints. I tried adding a DROP KEY {$row-&gt;CONSTRAINT_NAME} to the ALTER TABLE statement but then I received errors that the KEY did not exist. <br />
<br />
b) On altering one particular table to add in the new constraint I receive this error which is completely new to me:<br />
<br />
    ------------------------<br />
    LATEST FOREIGN KEY ERROR<br />
    ------------------------<br />
    111018  9:37:00 TRANSACTION:<br />
    TRANSACTION 0 797208, ACTIVE 3 sec, PROCESS NO 1079, OS thread id 140091990087424 inserting, thread declared inside INNODB 228<br />
    mysql TABLES IN USE 2, locked 2<br />
    317 LOCK struct(s), HEAP size 47088, 59493 ROW LOCK(s), UNDO LOG entries 53994<br />
    MySQL thread id 803, QUERY id 57650 localhost 127.0.0.1 root copy TO tmp TABLE<br />
    ALTER TABLE answers_users<br />
    				RENAME TO answers,<br />
    				CHANGE COLUMN answer_id option_id INT(11) UNSIGNED NOT NULL,<br />
    				ADD CONSTRAINT `fk-user-answers` FOREIGN KEY (user_id) REFERENCES clients(id),<br />
    				ADD CONSTRAINT `fk-question-answers` FOREIGN KEY (question_id) REFERENCES questions(id),<br />
    				ADD CONSTRAINT `fk-option-answers` FOREIGN KEY (option_id) REFERENCES OPTIONS(id)<br />
    FOREIGN KEY CONSTRAINT fails FOR TABLE `optimus`.&lt;result 2 WHEN explaining filename '#sql-437_323'&gt;:<br />
    ,<br />
      CONSTRAINT `fk-option-answers` FOREIGN KEY (`option_id`) REFERENCES `options` (`id`)<br />
    Trying TO ADD IN child TABLE, IN INDEX `fk-user_answer-answers` tuple:<br />
    DATA TUPLE: 2 FIELDS;<br />
     0: len 4; HEX 00000000; ASC     ;; 1: len 4; HEX 0000fb72; ASC    r;;<br />
    <br />
    But IN parent TABLE `optimus`.`options`, IN INDEX `PRIMARY`,<br />
    the closest MATCH we can find IS record:<br />
    PHYSICAL RECORD: n_fields 8; COMPACT FORMAT; info bits 0<br />
     0: len 4; HEX 00000062; ASC    b;; 1: len 6; HEX 0000000c29bb; ASC     ) ;; 2: len 7; HEX 0000000a3e093b; ASC     &gt; ;;; 3: len 4; HEX 00000016; ASC     ;; 4: len 25; HEX 28373230206f72204869676865722920457863656c6c656e74; ASC (720 OR Higher) Excellent;; 5: len 4; HEX 00000001; ASC     ;; 6: len 4; HEX 800002d0; ASC     ;; 7: len 1; HEX 80; ASC  ;;<br />
<br />
<br />
Is there a better way to clean out the old foreign keys? If not my next thought is to first convert the tables to MyISAM then drop the KEYS and then convert them back to Innodb.<br />
<br />
Thoughts?]]></description>
            <dc:creator>Noah Goodrich</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Tue, 18 Oct 2011 16:18:40 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,465992,465992#msg-465992</guid>
            <title>how to get only parent table record if no record in child row using Join (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,465992,465992#msg-465992</link>
            <description><![CDATA[ Hello,<br />
<br />
I am stuck with one scnerio where i have to prepare reports of all inquiries.<br />
<br />
i have several inquiries in Parent Table.<br />
<br />
For each inquiry there are materials in Inquiry_material table<br />
<br />
for each material in inquiry_material there are several sites in table inquiry_site<br />
<br />
and for each site in inquiry_site there are several services in inquiry_services table.<br />
<br />
Now i have some inquiries with no material and some inquiries with material but no site and sone site with no services.<br />
<br />
i wants to get all data from inquiry using join with child records and if there is no child record then blank record should be returned, i am trying my best to get the same but i think i am making some silly mistake and getting only those records which are having complete child records.<br />
<br />
Please suggest me to get empty records if there are is no record in child table.<br />
<br />
i am using this query.<br />
<br />
SELECT <br />
	inq.Inquiry_companym_code,<br />
	inq.inquiry_number,<br />
	imd.InquiryMaterialDetails_material_quantity,<br />
	isd.InquirySiteDetails_site_code,<br />
	issd.InquiryServiceDetails_service_code<br />
FROM inquiry inq<br />
JOIN inquiry_material imd<br />
	ON inq.Inquiry_ID = imd.InquiryMaterialDetails_inquiry_id<br />
INNER JOIN inquiry_site isd<br />
	ON imd.InquiryMaterialDetails_id = isd.InquirySiteDetails_inquirymaterialdetails_id<br />
INNER JOIN inquiry_service issd<br />
	ON issd.InquiryServiceDetails_inquirysitedetails_id = isd.InquirySiteDetails_id;]]></description>
            <dc:creator>ROHIT GUPTA</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 17 Oct 2011 05:45:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,453608,453608#msg-453608</guid>
            <title>Problem with Foreign key creator (1 reply)</title>
            <link>http://forums.mysql.com/read.php?135,453608,453608#msg-453608</link>
            <description><![CDATA[ Hi <br />
I am sitting on a program that need a some tables and I link between the tables.<br />
some of the FK work just fine but the one alwayes send me an error like i try to create a table ???<br />
the tables are:<br />
<br />
//table that hold a list of servers every server has a lot of application <br />
CREATE TABLE  IF NOT EXISTS <br />
`TestingApp`.`Server` (<br />
`ServerName` VARCHAR(20)  NOT NULL, <br />
`ServerPort` VARCHAR(5)  NOT NULL, <br />
`ServerType` int NOT NULL, <br />
`User` VARCHAR(20)  NOT NULL, <br />
`Password` VARCHAR(20)  NOT NULL, <br />
PRIMARY KEY (`ServerName`, `ServerPort`))<br />
//work Fine<br />
 <br />
//application that connect to server<br />
<br />
CREATE TABLE  IF NOT EXISTS <br />
`TestingApp`.`App` (<br />
`AppName` VARCHAR(20)  NOT NULL, <br />
`DisplayName` VARCHAR(20)  NOT NULL, <br />
`ServerPort` VARCHAR(5)   NOT NULL, <br />
`ServerName` VARCHAR(20)  NOT NULL, <br />
PRIMARY KEY (`BiAppName`))<br />
///work fine<br />
<br />
<br />
//the fk <br />
ALTER TABLE App <br />
ADD CONSTRAINT FK_App <br />
FOREIGN KEY (ServerName) REFERENCES Srever (ServerName)<br />
<br />
the error i get is:<br />
error Can't create table 'testingapp.#sql-1758_18' (errno: 150)<br />
i dont want to create table!!! i want to creat FK<br />
Help Please <br />
Thank you <br />
IziaMan]]></description>
            <dc:creator>itzik orfan</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 17 Oct 2011 06:01:53 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,433605,433605#msg-433605</guid>
            <title>Foreign key constraint failed when trying to add data to the normalised DB (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,433605,433605#msg-433605</link>
            <description><![CDATA[ Hi there!<br />
<br />
I'm working on a web portal that links to a database - users are able to upload and search for data within the database. I am working with XAMPP and the Server version is 5.5.8<br />
<br />
I am trying to create a normalised database with foreign keys by using InnoDB. I am currently adding data to the DB and the relations I have created I don't think are correct.<br />
<br />
<br />
I am not sure if I'm just being silly and the answer is really simple - but I just keep on going in circles. :wtf:<br />
<br />
It would be great if some one could help me out!<br />
<br />
There are two relationships in question:<br />
<br />
QUESTION ONE.<br />
<br />
tables involved are orders,  industry_sector, and industry_sub_sector. The industry_sector table has an optional 1:m relationship with the industry_sub_sector. orders table has a mandatory m:1 relationship with the industry_sector table. The industry_sector and the industry_sub_sector tables are complete as those are the only possible values to ever be included. The orders table so far is empty as I don't think I will be able to reference which IndustrySubSectorValue that particular OrderID will have.<br />
<br />
Possible Solution 1: I know that I could add another field to the orders table - IndustrySubSectorID - however that would create many NULL values as each order doesnt have to have a IndustrySubSectorValue (the relationship is mandatory).<br />
<br />
Possible Solution 2: I could make a bridge entity that would include the following fields: OrdersID, IndustySectorID, IndustrySubSectorID. However that would be creating a relationship with orders. Itsn't that incorrect as industry_sub_sector table should have a relationship industry_sector NOT orders?!<br />
<br />
I am not sure if I'm just being silly and the answer is really simple - but I just keep on going in circles. It would be great if you could help me out.<br />
<br />
QUESTION 2.<br />
<br />
This question is similar to question 1 in that it is about relationship between 3 interlinked tables, namely: orders, distribution_channel, and distribution_channel_details.<br />
<br />
The distribution_channel table has a 1:m mandatory relationship with orders table. The distribution_channel_details has an optional 1:m relationship with the distribution_channel table. (basically distribution channel details are the 'notes' on how that particular distribution channel was used for that specific order)<br />
<br />
Possible solution would be to do the same as question 1 - but that would create null values as each order doesnt require a DistributionDetailValue.<br />
<br />
So basically: I am unable to add rows to the orders table because foreign key constraint failed. The relationships I have in place are wrong. I am looking for help with the relationships between:<br />
<br />
1. orders, industry_sector, and industry_sub_sector<br />
2. orders, distribution_channel, and distribution_channel_details<br />
<br />
I realise I could easily add both DistributionChannelDetailID and IndustrySubSectorID to the orders table - however that would creat a large amount of NULL values as both DistributionChannelDetailValue and IndustrySubSectorValue are optional for each order added.<br />
<br />
So simply put : do I create a bridge entity that is directly linked to the orders table for the industry_sub_sector and the distribution_channel_details respectively ??<br />
<br />
If you need any more detail about either question please let me know, and sorry if I havent explained it all to clearly ;)<br />
<br />
Thanks so much! Chelsea]]></description>
            <dc:creator>Chelsea Sanders</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Fri, 09 Sep 2011 08:37:58 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,432562,432562#msg-432562</guid>
            <title>cyclic reference (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,432562,432562#msg-432562</link>
            <description><![CDATA[ Hello!<br />
<br />
I'm in doubt about my model. Here it is:<br />
<a href="http://i29.fastpic.ru/big/2011/0831/ee/3a04def71dd8ac99cd90a97944f976ee.png"  rel="nofollow">http://i29.fastpic.ru/big/2011/0831/ee/3a04def71dd8ac99cd90a97944f976ee.png</a><br />
<br />
`Products` can pertain to multiple `Categories`, hence n:m relationship `Categories_has_Products`. Each category has a set of `CategoryParams`, mandatory for each product, that belongs to that category (there's no a priori info about how many and which params a category can get and list may change frequently).<br />
Then, when I'm adding a table `ProductsParams` to list params values for products, i get references to both `Products` and `CategoriesParams`. And a kind of cycle shows up in FKs.<br />
<br />
I have no idea how not to make such a cycle...]]></description>
            <dc:creator>Boris Murashin</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Wed, 31 Aug 2011 19:53:56 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,431864,431864#msg-431864</guid>
            <title>ALTER TABLE NOCHECK CONSTRAINT (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,431864,431864#msg-431864</link>
            <description><![CDATA[ Does MYSQL support the use of this SQL statement:<br />
ALTER TABLE `tablename` NOCHECK CONSTRAINT `foreignkeyname`;<br />
<br />
In essence I wish to have a foreign key constraint between two tables, but want to not have it actually be enforced.  Think of it as a drop-down type box filled with values from a related table, but the user is able to type in it freely and not be limited to the list.<br />
<br />
Thanks in advance,<br />
Mark]]></description>
            <dc:creator>Mark Oberg</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Thu, 25 Aug 2011 13:50:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,431650,431650#msg-431650</guid>
            <title>on delete cascade differences (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,431650,431650#msg-431650</link>
            <description><![CDATA[ hey<br />
<br />
what are the differences, if there are among these three statements?<br />
<br />
Code:<br />
<br />
key xyz(sid), constraint xyz foreign key(sid) references Singers(id) on delete cascade;<br />
<br />
Code:<br />
<br />
foreign key(sid) references Singers(id) on delete cascade;<br />
<br />
Code:<br />
<br />
index idx_dr(sid),foreign key(sid) references Singers(id) on delete cascade;<br />
<br />
thanks]]></description>
            <dc:creator>muhamad eawedat</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Tue, 23 Aug 2011 22:41:45 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?135,429804,429804#msg-429804</guid>
            <title>issues with table joins (no replies)</title>
            <link>http://forums.mysql.com/read.php?135,429804,429804#msg-429804</link>
            <description><![CDATA[ A]]></description>
            <dc:creator>Gaurav J</dc:creator>
            <category>Foreign Keys (Referential Integrity)</category>
            <pubDate>Mon, 08 Aug 2011 02:18:41 +0000</pubDate>
        </item>
    </channel>
</rss>
