2
對於冗長的代碼,我表示歉意,但我試圖創建一個審計表(稱爲aud_candles),它是「蠟燭」的副本,但是具有新的唯一鍵,aud_can_id。在「蠟燭」更新發生之前,我希望觸發器將該行的當前狀態保存在「aud_candles」中。MySQL:列計數與第1行的值計數不匹配
Target Server Type : MySQL
Target Server Version : 50165
File Encoding : utf-8
Date: 11/07/2012 23:05:38 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `candles`
-- ----------------------------
DROP TABLE IF EXISTS `candles`;
CREATE TABLE `candles` (
`can_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`can_name` varchar(255) NOT NULL,
`can_description` varchar(1024) NOT NULL,
`can_dye_id` int(10) unsigned NOT NULL,
`can_snt_id` int(10) unsigned NOT NULL,
`can_wick_id` int(10) unsigned NOT NULL,
`can_wax_id` int(10) unsigned NOT NULL,
`can_retail_cost` float(10,2) NOT NULL,
`can_materials_cost` float(10,2) NOT NULL,
`can_dye_used` float(10,2) NOT NULL,
`can_snt_used` float(10,2) NOT NULL,
`can_wick_used` float(10,2) NOT NULL,
`can_wax_used` float(10,2) NOT NULL,
`can_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`can_id`),
KEY `idx_candles_dyes_id` (`can_dye_id`) USING BTREE,
KEY `idx_candles_scents_id` (`can_snt_id`) USING BTREE,
KEY `idx_candles_wax_id` (`can_wax_id`) USING BTREE,
KEY `fk_candles_wick_id` (`can_wick_id`),
CONSTRAINT `fk_candles_dye_id` FOREIGN KEY (`can_dye_id`) REFERENCES `dyes` (`dye_id`),
CONSTRAINT `fk_candles_scent_id` FOREIGN KEY (`can_snt_id`) REFERENCES `scents` (`snt_id`),
CONSTRAINT `fk_candles_wax_id` FOREIGN KEY (`can_wax_id`) REFERENCES `wax` (`wax_id`),
CONSTRAINT `fk_candles_wick_id` FOREIGN KEY (`can_wick_id`) REFERENCES `wicks` (`wic_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
delimiter ;;
CREATE TRIGGER `trg_audit_update_candles` BEFORE UPDATE ON `candles` FOR EACH ROW BEGIN
INSERT INTO aud_candles
(can_id,
can_name,
can_description,
can_dye_id,
can_snt_id,
can_wick_id,
can_wax_id,
can_materials_cost,
can_retail_cost,
can_updated)
VALUES
(OLD.can_id,
OLD.can_name,
OLD.can_description,
OLD.can_dye_id,
OLD.can_snt_id,
OLD,can_wick_id,
OLD.can_wax_id,
OLD.can_materials_cost,
OLD.can_retail_cost,
OLD.can_updated);
END;
;;
delimiter ;
-- ----------------------------
-- Records of `candles`
-- ----------------------------
BEGIN;
INSERT INTO `candles` VALUES ('1', 'Test Name', 'Test Description', '12', '10', '102', '1', '0.00', '0.00', '5', '25.00', '15.00', '500.00', '2012-11-07 13:29:02');
COMMIT;
DROP TABLE IF EXISTS `aud_candles`;
CREATE TABLE `aud_candles` (
`aud_can_id` int(11) NOT NULL AUTO_INCREMENT,
`can_id` int(10) unsigned NOT NULL,
`can_name` varchar(255) CHARACTER SET latin1 NOT NULL,
`can_description` varchar(1024) CHARACTER SET latin1 NOT NULL,
`can_dye_id` int(10) unsigned NOT NULL,
`can_snt_id` int(10) unsigned NOT NULL,
`can_wick_id` int(10) unsigned NOT NULL,
`can_wax_id` int(10) unsigned NOT NULL,
`can_retail_cost` float(10,2) NOT NULL,
`can_materials_cost` float(10,2) NOT NULL,
`can_dye_used` float(10,2) NOT NULL,
`can_snt_used` float(10,2) NOT NULL,
`can_wick_used` float(10,2) NOT NULL,
`can_wax_used` float(10,2) NOT NULL,
PRIMARY KEY (`aud_can_id`),
KEY `idx_candles_dyes_id` (`can_dye_id`) USING BTREE,
KEY `idx_candles_scents_id` (`can_snt_id`) USING BTREE,
KEY `idx_candles_wax_id` (`can_wax_id`) USING BTREE,
KEY `fk_candles_wick_id` (`can_wick_id`),
CONSTRAINT `fk_aud_candles_dye_id` FOREIGN KEY (`can_dye_id`) REFERENCES `dyes` (`dye_id`),
CONSTRAINT `fk_aud_candles_scent_id` FOREIGN KEY (`can_snt_id`) REFERENCES `scents` (`snt_id`),
CONSTRAINT `fk_aud_candles_wax_id` FOREIGN KEY (`can_wax_id`) REFERENCES `wax` (`wax_id`),
CONSTRAINT `fk_aud_candles_wick_id` FOREIGN KEY (`can_wick_id`) REFERENCES `wicks` (`wic_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SET FOREIGN_KEY_CHECKS = 1;
UPDATE candles set can_name = 'Test Name 2' WHERE can_id = 1;
在進行更新我收到:
錯誤
列數並不在行1
匹配值計數如果我刪除觸發一切工作正常,所以它必須與觸發器相關?
這將導致山坳和值計數不匹配,這是我認爲在任何其他事情之前都會被驗證,所以它會在表錯誤中不存在列之前返回此錯誤。 – invertedSpear
非常感謝。你絕對正確 - 我不知道我是如何錯過的! – Morrolan