Mysql:执行以下提到的事情时,我会
不正确的整数值:“。 42。 '代表第1行的'user_id'列)
此错误并且无法插入记录,为什么会这样?
CREATE TABLE `test` (
`uid` INT PRIMARY KEY AUTO_INCREMENT,
`uname` VARCHAR(25) NOT NULL,
`urole` VARCHAR(25) NOT NULL,
`udesig` VARCHAR(25) NOT NULL,
`usalary` INT(6) NOT NULL
);
CREATE TABLE `audit_trail_test` (
`_id` INT PRIMARY KEY AUTO_INCREMENT,
`_group_id` INT(5) NOT NULL,
`uid` INT NOT NULL,
`uname` VARCHAR(25) NOT NULL,
`urole` VARCHAR(25) NOT NULL,
`udesig` VARCHAR(25) NOT NULL,
`usalary` INT(6) NOT NULL
);
CREATE TABLE `audit_trail_revisions` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`user_id` INT NOT NULL,
`time` DATETIME NOT NULL
);
DELIMITER $$
CREATE PROCEDURE create_revision_record()
BEGIN
IF @group_id IS NULL THEN
INSERT INTO `audit_trail_revisions`
(user_id, `time`)
VALUES
(@user_id, @time);
SET @group_id = LAST_INSERT_ID();
END IF;
END;
CREATE TRIGGER `test_insert` AFTER INSERT ON `test`
FOR EACH ROW BEGIN
CALL create_revision_record();
INSERT INTO `audit_trail_test`
(
uid,
uname,
urole,
udesig,
usalary,
_group_id
)
VALUES
(
NEW.uid,
NEW.uname,
NEW.urole,
NEW.udesig,
NEW.usalary,
@group_id
);
END;
$$
CREATE TRIGGER `test_update` AFTER UPDATE ON `test`
FOR EACH ROW BEGIN
CALL create_revision_record();
INSERT INTO `audit_trail_test`
(
uid,
uname,
urole,
udesig,
usalary ,
_group_id
)
VALUES
(
NEW.uid,
NEW.uname,
NEW.urole,
NEW.udesig,
NEW.usalary,
@group_id
);
END;
$$
DELIMITER $$
CREATE PROCEDURE delete_revision_record()
BEGIN
IF @group_id IS NULL THEN
INSERT INTO `audit_trail_revisions`
(user_id, `time`)
VALUES
(@user_id, @time);
SET @group_id = LAST_INSERT_ID();
END IF;
END;
CREATE TRIGGER `test_delete` AFTER DELETE ON `test`
FOR EACH ROW BEGIN
CALL delete_revision_record();
DELETE FROM `audit_trail_test` WHERE uid=_id;
END;
$$
query : 1.SET @user_id = ' . 42 . ', @time = NOW();
query : 2.insert into test(uname,urole,udesig,usalary) values('abc','cba','bac',10000);