mysql insert触发器问题
怎样用mysql语句创建一个insert数据时的触发器,当我向user表里插入一条数据时,怎样让它触发project表里也插入一条数据,并且project表里插入的数据的...
怎样用mysql语句创建一个insert数据时的触发器,当我向user表里插入一条数据时,怎样让它触发project表里也插入一条数据,并且project表里插入的数据的username与project表里的username一样。如我用sql server 写的:
create trigger trig_user
on users
after insert
as
declare @dh varchar(30)
set @dh=(select username from inserted)
insert into project (username,teamname,pro_name)
values(@dh,@dh,@dh)
怎样在mysql里实现一样的功能?求指教? 展开
create trigger trig_user
on users
after insert
as
declare @dh varchar(30)
set @dh=(select username from inserted)
insert into project (username,teamname,pro_name)
values(@dh,@dh,@dh)
怎样在mysql里实现一样的功能?求指教? 展开
3个回答
展开全部
CREATE TRIGGER testref AFTER INSERT ON users
FOR EACH ROW BEGIN declare @dh varchar(30) select NEW.username into @dh from NEW; insert into project (username,teamname,pro_name) values(@dh,@dh,@dh); END@dh 是插入username的值
FOR EACH ROW BEGIN declare @dh varchar(30) select NEW.username into @dh from NEW; insert into project (username,teamname,pro_name) values(@dh,@dh,@dh); END@dh 是插入username的值
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-10-25
展开全部
类似如下:
CREATE TRIGGER `trig_user` AFTER UPDATE ON `users` FOR EACH ROW BEGIN
insert into project (username,teamname,pro_name) values (NEW.username,NEW.username,NEW.username);
END
CREATE TRIGGER `trig_user` AFTER UPDATE ON `users` FOR EACH ROW BEGIN
insert into project (username,teamname,pro_name) values (NEW.username,NEW.username,NEW.username);
END
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上正解!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询