delimiter // create trigger cnt after insert on tc_contract for each row begin select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;if @num >0 and @num <3 then update tc_account set account_status = 2 where account_id = new.account_id; end if; end//
我用的是 mysql query browser 工具,用下面这段代码还是报错了呀:create trigger cnt after insert on tc_contract for each row begin select count(*) into @num from tc_contract group by account_id where account_id = new.account_id; if @num >0 and @num <3 then update tc_account set account_status = 2 where account_id = new.account_id; end if; end
我把整段复制进去也还是报错: delimiter // create trigger cnt after insert on tc_contract for each row begin select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;if @num >0 and @num <3 then update tc_account set account_status = 2 where account_id = new.account_id; end if; end//
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where account_id = new.account_id; if @num >0 and @num <3 then update tc_accou' at line 4
select count(*) into @num from tc_contract where account_id = new.account_id group by account_id ;
trigger调试思路: 1。sql是不是正确, 2。trigger语法, update tc_account set account_status = '2' where account_id = new.account_id;if @num >0 and @num <3 then你真不如分二步写,这样有的环境解释不过的。
以下语句,调试已成功,请参考: create trigger portGo after insert on wc for each row begin select count(*) into @num from dataIn where port = new.name; if @num=0 then insert into dataIn values ('4',new.name); end if; end$
create trigger cnt after insert on tc_contract
for each row
begin
select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;if @num >0 and @num <3 then
update tc_account set account_status = 2 where account_id = new.account_id;
end if;
end//
for each row
begin
select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;
if @num >0 and @num <3 then
update tc_account set account_status = 2 where account_id = new.account_id;
end if;
end
delimiter //
create trigger cnt after insert on tc_contract
for each row
begin
select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;if @num >0 and @num <3 then
update tc_account set account_status = 2 where account_id = new.account_id;
end if;
end//
if @num >0 and @num <3 then
update tc_accou' at line 4
1。sql是不是正确,
2。trigger语法,
update tc_account set account_status = '2' where account_id = new.account_id;if @num >0 and @num <3 then你真不如分二步写,这样有的环境解释不过的。
create trigger portGo
after insert on wc
for each row
begin
select count(*) into @num from dataIn where port = new.name;
if @num=0 then
insert into dataIn values ('4',new.name);
end if;
end$