原来表的FK约束是这样的
foreign key (topic_id) references content(tontent_id)
现在我想加个 on delete cascade 约束,怎么加呢, alter modify 好像不行。我删除FK 也不行啊, 我用 alter table tablename drop foreign key topic_id
foreign key (topic_id) references content(tontent_id)
现在我想加个 on delete cascade 约束,怎么加呢, alter modify 好像不行。我删除FK 也不行啊, 我用 alter table tablename drop foreign key topic_id
alter table tt drop CONSTRAINT topic_id
ALTER TABLE tbl1 ADD CONSTRAINT fk_name FOREIGN KEY index (col1) REFERENCES tbl2(col2) referential_actions;
ALTER TABLE tbl DROP FOREIGN KEY fk_name;
`review_id` int(11) NOT NULL AUTO_INCREMENT,
`reviw_user` varchar(20) NOT NULL,
`topic_id` int(11) NOT NULL,
`reviw_date` datetime NOT NULL,
`review_content` text NOT NULL,
PRIMARY KEY (`review_id`),
KEY `topic_id` (`topic_id`),
CONSTRAINT `review_ibfk_1` FOREIGN KEY (`topic_id`) REFERENCES `content` (`content_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
这是我的建表语句, 就想删除 那个外键约束
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0mysql> alter table `review` add CONSTRAINT `review_ibfk_1` FOREIGN KEY (`topic_id`) REFERENCES `content` (`content_id`) on delete cascade ;
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0