我有两张PK和FK关系的表,如下所示。
CREATE TABLE `sector_tab` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` smallint(6) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
CREATE TABLE `ticker_tab` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_title` varchar(255) DEFAULT NULL,
`sector_num` smallint(6) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ind_sector_number` (`sector_num`),
CONSTRAINT `ticker_tab_ibfk_1` FOREIGN KEY (`sector_num`)
REFERENCES `sector_tab` (`code`),
) ENGINE=InnoDB AUTO_INCREMENT=4096 DEFAULT CHARSET=utf8;
现在,当我想截断' sector_tab'表,但由于PK-FK关系我得到错误,所以我想用SET FOREIGN_KEY_CHECKS = 0禁用它,但我无法做到但是当我在程序中提到FOREIGN_KEY_CHECKS = 0时,如下所示并运行它的工作。怎么会发生这种情况?
CREATE PROCEDURE `proc_FK_diable`()<br>
BEGIN
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE sector_tab;
SET FOREIGN_KEY_CHECKS=1;<br>
END
我正在使用Mysql Query Browser 1.1
答案 0 :(得分:0)
delimiter $
CREATE PROCEDURE proc_FK_diable()
BEGIN
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE sector_tab;
SET FOREIGN_KEY_CHECKS = 1;
END
$