Ver Mensaje Individual
  #25 (permalink)  
Antiguo 14/09/2009, 04:50
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Delete u poco extraño

Muchacho, como que no lo vez. Copio integramente lo que huesos52 te indico

Código mysql:
Ver original
  1. mysql> CREATE TABLE categorias(cod INTEGER PRIMARY KEY,nombre TEXT,padre_cat INTEGER,FOREIGN key (padre_cat) REFERENCES categorias(cod) on DELETE CASCADE);
  2. Query OK, 0 rows affected (0.02 sec)
  3.  
  4. mysql> INSERT INTO categorias VALUES(1,'daniel',NULL);
  5. Query OK, 1 row affected (0.00 sec)
  6.  
  7. mysql> INSERT INTO categorias VALUES(2,'sara',1);
  8. Query OK, 1 row affected (0.00 sec)
  9.  
  10. mysql> INSERT INTO categorias VALUES(3,'taty',NULL);
  11. Query OK, 1 row affected (0.00 sec)
  12.  
  13. mysql> SELECT *FROM categorias;
  14. +-----+--------+-----------+
  15. | cod | nombre | padre_cat |
  16. +-----+--------+-----------+
  17. |   1 | daniel |      NULL |
  18. |   2 | sara   |         1 |
  19. |   3 | taty   |      NULL |
  20. +-----+--------+-----------+
  21. 3 rows IN SET (0.00 sec)
  22.  
  23. mysql> DELETE FROM categorias WHERE cod=1;
  24. Query OK, 1 row affected (0.01 sec)
  25.  
  26. mysql> SELECT *FROM categorias;
  27. +-----+--------+-----------+
  28. | cod | nombre | padre_cat |
  29. +-----+--------+-----------+
  30. |   3 | taty   |      NULL |
  31. +-----+--------+-----------+
  32. 1 row IN SET (0.00 sec)
  33.  
  34. mysql>

Todo esto es una sola tabla. No hay dos tablas aqui, solo una.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos