MySQL:列数与第1行的值计数不匹配

时间:2012-11-07 23:35:21

标签: mysql sql

我为冗长的代码道歉,但我正在尝试创建一个审计表(称为aud_candles),它与'蜡烛'重复,但带有一个新的唯一键aud_can_id。在对'蜡烛'进行更新之前,我希望触发器将该行的当前状态保存在'aud_candles'中。

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行的值计数不匹配

如果我移除触发器一切正常,那么它必须与触发器有关吗?

1 个答案:

答案 0 :(得分:1)

我不知道这是否是拼写错误,但你在comma条款的某处使用period代替values

....
OLD.can_snt_id, 
OLD,can_wick_id,  -- << here, it should be period.
OLD.can_wax_id, 
...