我 现在有一个表user,字段有自增uid,username,suid。 现在执行insert into user(username)values('1111').现在我想要的是一个触发器 是在插入的时候执行
suid=这个插入的自增uid。delimiter $
CREATE TRIGGER update_user_suid
AFTER INSERT on user
for each ROW
BEGIN
declare lastid int;
select last_insert_id() into lastid;
set suid = lastid where uid = lastid;
end $我是这样写的 但是会报Unknown system variable 'uid'的错误。
suid=这个插入的自增uid。delimiter $
CREATE TRIGGER update_user_suid
AFTER INSERT on user
for each ROW
BEGIN
declare lastid int;
select last_insert_id() into lastid;
set suid = lastid where uid = lastid;
end $我是这样写的 但是会报Unknown system variable 'uid'的错误。
CREATE TRIGGER update_user_suid
AFTER INSERT on user
for each ROW
BEGIN
set new.suid=last_insert_id();
end $
报Updating of NEW row is not allowed in after trigger 这个错误~
CREATE TRIGGER update_user_suid
before INSERT on user
for each ROW
BEGIN
set new.suid=last_insert_id();
end $
set new.suid=last_insert_id();
delimiter $
CREATE TRIGGER a
before INSERT on table
for each ROW
BEGIN
DECLARE maxid int;
SELECT max(id) into maxid from table;
if new.suid = '' then
set new.suid = maxid+1;
end if;
end $
这样能实现。