+ -
当前位置:首页 → 问答吧 → 小弟求救,级联删除不起作用????

小弟求救,级联删除不起作用????

时间:2008-07-25

来源:互联网

我的语句如下,所照着手册写的,但是级联删除不起作用,在线等高人搭救,谢谢.....
CREATE TABLE `jos_sf_magzine` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL DEFAULT '',
  `publishdate` DATE  NULL ,
  `introtext` text  NOT NULL DEFAULT '',
  `toc` text NOT NULL DEFAULT '',
  `cover` varchar(100)   NULL ,
  `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

CREATE TABLE `jos_sf_magzine_article` (
  `aid` int(11) NOT NULL auto_increment,
  `magzineid` int(11) NOT NULL DEFAULT '0',
  `title` varchar(255) NOT NULL DEFAULT '',
  `content` text  NOT NULL DEFAULT '',
  `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY  (`aid`),
  INDEX (`magzineid`),
  FOREIGN KEY (`magzineid`)  REFERENCES jos_sf_magzine(`id`)  ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

作者: qianjin03   发布时间: 2008-07-24

mysql> CREATE TABLE `jos_sf_magzine` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL DEFAULT '',
  `publishdate` DATE  NULL ,
  `introtext` text  NOT NULL DEFAULT '',
  `toc` text NOT NULL DEFAULT '',
  `cover` varchar(100)   NULL ,
  `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected

mysql> CREATE TABLE `jos_sf_magzine_article` (
  `aid` int(11) NOT NULL auto_increment,
  `magzineid` int(11) NOT NULL DEFAULT '0',
  `title` varchar(255) NOT NULL DEFAULT '',
  `content` text  NOT NULL DEFAULT '',
  `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY  (`aid`),
  INDEX (`magzineid`),
  FOREIGN KEY (`magzineid`)  REFERENCES jos_sf_magzine(`id`)  ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected

mysql> select * from jos_sf_magzine;
+----+------+-------------+-----------+-----+-------+---------------------+
| id | name | publishdate | introtext | toc | cover | created             |
+----+------+-------------+-----------+-----+-------+---------------------+
|  1 |      | NULL        |           |     | NULL  | 0000-00-00 00:00:00 |
|  2 |      | NULL        |           |     | NULL  | 0000-00-00 00:00:00 |
|  3 |      | NULL        |           |     | NULL  | 0000-00-00 00:00:00 |
+----+------+-------------+-----------+-----+-------+---------------------+
3 rows in set

mysql> select * from jos_sf_magzine_article;
+-----+-----------+-------+---------+---------------------+
| aid | magzineid | title | content | created             |
+-----+-----------+-------+---------+---------------------+
|   1 |         1 |       |         | 0000-00-00 00:00:00 |
|   2 |         1 |       |         | 0000-00-00 00:00:00 |
|   3 |         2 |       |         | 0000-00-00 00:00:00 |
|   4 |         2 |       |         | 0000-00-00 00:00:00 |
+-----+-----------+-------+---------+---------------------+
4 rows in set

mysql> delete from jos_sf_magzine where id = '1';
Query OK, 1 row affected

mysql> select * from jos_sf_magzine_article;
+-----+-----------+-------+---------+---------------------+
| aid | magzineid | title | content | created             |
+-----+-----------+-------+---------+---------------------+
|   3 |         2 |       |         | 0000-00-00 00:00:00 |
|   4 |         2 |       |         | 0000-00-00 00:00:00 |
+-----+-----------+-------+---------+---------------------+
2 rows in set

作者: devotedsky   发布时间: 2008-08-01

热门下载

更多