"R.Dobson" <[EMAIL PROTECTED]> wrote:
> mmm, i've just tried the example within the mysql docs:
> 
> CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB;
> CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id),
>             FOREIGN KEY (parent_id) REFERENCES parent(id)
>             ON DELETE cascade
> ) TYPE=INNODB;
> 
> Now, insert a couple of lies of data:
> 
> mysql> insert into parent values(1);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into parent values(2);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into parent values(3);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into child values(1,1);
> Query OK, 1 row affected (0.01 sec)
> 
> mysql> insert into child values(2,2);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into child values(3,3);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> select * from child;
> +------+-----------+
> | id   | parent_id |
> +------+-----------+
> |    1 |         1 |
> |    2 |         2 |
> |    3 |         3 |
> +------+-----------+
> 3 rows in set (0.00 sec)
> 
> mysql> select * from parent;
> +----+
> | id |
> +----+
> |  1 |
> |  2 |
> |  3 |
> +----+
> 3 rows in set (0.00 sec)
> 
> 
> 
> 
> When I come to try to delete some data from the parent table i'm getting 
> errors as in:
> 
> mysql> delete from parent where id=1;
> ERROR 1217: Cannot delete a parent row: a foreign key constraint fails
> 
> any thoughts?
> 

Worked perfect for me:

mysql> delete from parent where id=1;
Query OK, 1 row affected (0.04 sec)

mysql> select * from child;
+------+-----------+
| id   | parent_id |
+------+-----------+
|    2 |         2 |
|    3 |         3 |
+------+-----------+
2 rows in set (0.02 sec)

mysql> select * from parent;
+----+
| id |
+----+
|  2 |
|  3 |
+----+
2 rows in set (0.00 sec)

What version of MySQL do you use?


-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Victoria Reznichenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com





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

Reply via email to