我 现在有一个表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'的错误。
解决方案 »
- java程序如何连接使用PL/Proxy方式集群的数据库
- 执行function时报错(subtransactions in a transaction)
- DB2 请问如何在查找出来的数据中加上%
- mysql 支持分布式事务么????
- mysql导入数据库问题
- 左外连接+分组+聚合函数- -...小弟有点迷茫
- java.sql.SQLException: [Microsoft][ODBC Microsoft Access 驱动程序] 参数不足,期待是 1。
- Mysql的服务启动后,用mysql.exe无法建立数据库,总是说access denied,请问是那的问题?
- C# Mysql第二次连接很慢
- Navicat如何将导出的数据表重命名
- 大神们 看过来! java程序连接mysql读取不了值为'1'或者'x'这种值 求解答
- mysql的group_concat函数问题
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 $
这样能实现。