mysql怎么用触发器实现,在插入2个字段时,同时生成第3个字段的数据,然后插入到表中 5
比如我有一个表,3个字段,H00,H01,thatDay,当我插入H00,H01的数据时,触发器自动生成thatDay字段的数据,然后将生成的数据,和我像插入的数据,一起...
比如我有一个表,3个字段,H00, H01, thatDay, 当我插入H00, H01的数据时,触发器自动生成thatDay字段的数据,然后将生成的数据,和我像插入的数据,一起写入表中
表
create table _hourYield(
id int(2) primary key auto_increment,
H00 int(4) not null,
H01 int(4) not null,
thatDay int(4) null
)engine = innodb;
触发器
create trigger sumH after insert on _houryield for each row update _houryield set new.thatDay = new.H00 + new.H01;
SQL插入语句
insert into _houryield(H00, H01) values(10, 20);
错误提示
ERROR 1442 (HY000): Can't update table '_houryield' in stored
function/trigger because it is already used by statement which invoked
this stored function/trigger. 展开
表
create table _hourYield(
id int(2) primary key auto_increment,
H00 int(4) not null,
H01 int(4) not null,
thatDay int(4) null
)engine = innodb;
触发器
create trigger sumH after insert on _houryield for each row update _houryield set new.thatDay = new.H00 + new.H01;
SQL插入语句
insert into _houryield(H00, H01) values(10, 20);
错误提示
ERROR 1442 (HY000): Can't update table '_houryield' in stored
function/trigger because it is already used by statement which invoked
this stored function/trigger. 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询