PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Foreign Keys Don't Work?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Foreign Keys Don't Work?

Réponse
 
LinkBack Outils de la discussion
Vieux 18/04/2006, 11h29   #1
clops
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Foreign Keys Don't Work?

Dear Collegues,

can anyone explain me WHY the following set of instructions does not
spit any errors (MySQL 5.017) -- the second insert should not have
worked as it references a non-existing record!

mysql> CREATE TABLE struct(
-> node_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> parent_node_id INT UNSIGNED REFERENCES
ep_catalog_structure.node_id ON DELETE CASCADE ON UPDATE CASCADE,
->
-> # Labels
-> name VARCHAR(255) NOT NULL,
->
-> PRIMARY KEY(node_id)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.03 sec)

mysql> insert into struct set name = 'Hello World';
Query OK, 1 row affected (0.00 sec)

mysql> insert into struct set name = 'Hello World Child',
parent_node_id = 1;
Query OK, 1 row affected (0.03 sec)

mysql> insert into struct set name = 'Hello World Child',
parent_node_id = 6;
Query OK, 1 row affected (0.00 sec)

mysql> select * from struct;
+---------+----------------+-------------------+
| node_id | parent_node_id | name |
+---------+----------------+-------------------+
| 1 | NULL | Hello World |
| 2 | 1 | Hello World Child |
| 3 | 6 | Hello World Child |
+---------+----------------+-------------------+
3 rows in set (0.00 sec)

mysql>

  Réponse avec citation
Vieux 18/04/2006, 11h36   #2
clops
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Foreign Keys Don't Work?

of course I reference "struct.node_id" -- just a small typo while
renaming the table for this post

  Réponse avec citation
Vieux 18/04/2006, 19h39   #3
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Foreign Keys Don't Work?

clops wrote:
> mysql> CREATE TABLE struct(
> -> node_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
> -> parent_node_id INT UNSIGNED REFERENCES
> struct.node_id ON DELETE CASCADE ON UPDATE CASCADE,

.. . .

Normally the syntax is "REFERENCES tablename(columnname)", not
"tablename.columnname".

See http://dev.mysql.com/doc/refman/5.0/...ate-table.html

I'm not sure how MySQL is interepreting this CREATE TABLE, or why it
didn't give you an error. But it may not be enforcing what you think
it's enforcing.

Regards,
Bill K.
  Réponse avec citation
Vieux 19/04/2006, 08h11   #4
Heikki Tuuri
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Foreign Keys Don't Work?

Hi!

It is this bug:

http://bugs.mysql.com/bug.php?id=13301

MySQL still does not give a warning for syntax that does not work.

Best regards,

Heikki

Oracle Corp./Innobase Oy
InnoDB - transactions, row level locking, and foreign keys for MySQL

InnoDB Hot Backup - a hot backup tool for InnoDB which also backs up MyISAM
tables
http://www.innodb.com/order.php

"Bill Karwin" <bill@karwin.com> kirjoitti
viestissä:e23bov0gv1@enews2.newsguy.com...
> clops wrote:
>> mysql> CREATE TABLE struct(
>> -> node_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
>> -> parent_node_id INT UNSIGNED REFERENCES
>> struct.node_id ON DELETE CASCADE ON UPDATE CASCADE,

> . . .
>
> Normally the syntax is "REFERENCES tablename(columnname)", not
> "tablename.columnname".
>
> See http://dev.mysql.com/doc/refman/5.0/...ate-table.html
>
> I'm not sure how MySQL is interepreting this CREATE TABLE, or why it
> didn't give you an error. But it may not be enforcing what you think it's
> enforcing.
>
> Regards,
> Bill K.



  Réponse avec citation
Vieux 20/04/2006, 13h50   #5
clops
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Foreign Keys Don't Work?

thanks!!

I got it working with the normal sytax "FOREIGN KEY (col) REFERENCES
blablabla"

regards,

ak

  Réponse avec citation
Vieux 20/04/2006, 14h38   #6
clops
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Foreign Keys Don't Work?

thanks!!

I got it working with the normal sytax "FOREIGN KEY (col) REFERENCES
blablabla"

regards,

ak

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12144 seconds with 14 queries