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

标签 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;

执行更新时我收到:

错误

Column count doesn't match value count at row 1

如果我删除触发器一切正常,那么它一定与触发器相关吗?

最佳答案

我不知道这是不是打字错误,但你在 values 子句的某处使用了 comma 而不是 period

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

关于MySQL:列数与第 1 行的值数不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13280164/

相关文章:

PHP MySQL 事务

javascript - 从表格单元格更新数据库而不刷新页面

php - MySQL 的 LOWER() 和 PHP 的 mb_strtolower() 返回相同的结果?

按连续外键​​值分组的 SQL 查询

sql - Progress DB SQL 的 LIKE 运算符

asp.net - 小型数据库系统作为 ASP.NET 站点的 ACL

php - PDO查看查询的插入详细信息

mysql - 使用单个 MySQL 查询更新带有前缀 + 计数器的单元格值

sql - 如何合并不相关的表,但对公共(public)列类型进行排序?

mysql - 在表的行中设置迭代值