是否有可能创建一个作用于2个表的触发器 [英] is it possible to create a single trigger which acts on 2 tables

查看:71
本文介绍了是否有可能创建一个作用于2个表的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我分别有3个表user,admin,tpyref.
用户表包含以下字段(uid,uemail,uwarned,upwd).
Admin表由(adminid,adminpwd)组成,typref由(refid,usertype)组成.

现在,我的问题是我可以创建一个触发器同时对用户表和管理员表起作用,并且无论何时对用户表或管理员表进行任何更改,即发生(插入/更新/删除),这都会反映在表中Typref.

另外,表typref的表usertype字段应插入一个值"user"或"admin",这取决于表中任何一个表上发生的操作.我的意思是说,如果在用户表中插入值,则必须在usertype字段中插入值"user" tyref的.

与管理表相同,即,只要在管理表中发生更改,就会插入值"admin",而将"admin"值插入到tpref表中.现在的问题是如何确定要插入哪个值的"admin"或"user".我的意思是说,必须根据表中任何一个发生的更改插入"user"或"admin"值,如何知道在哪个表中进行更改?希望大家知道我在说什么吗?

Hi,
I have 3 tables user,admin,tpyref respectively.
User table consist of following fields (uid,uemail,uwarned,upwd).
Admin table consist of (adminid,adminpwd)and typref consist of (refid,usertype).

Now,my question is can i create a single trigger which would act on both user and admin tables and whenever a change is made in any of the table either user or admin i.e (insert/update/delete) happens then that is reflected in table typref.

Also the field usertype of table typref should insert a value either "user"or"admin" depending the operation happening on either of table.I mean to say if values are inserted in user table then value "user" must get inserted in usertype field of tyref.

Same with admin table i.e value "admin" gets inserted whenever changes happens in admin table , "admin" values gets inserted in tpref table. Now problem is how to determine which values get inserted "admin" or "user". I mean to say value "user" or "admin" must gets inserted depending upon changes happening in either of table,how to know whether in which table change is happening ? I hope you people get to know what i am saying?

推荐答案

不,您不能创建单个可重复使用的触发器,而根据您的描述,它不会反正工作.您需要为每个表,用户和admin创建一个触发器,并使其插入到typeref表中.
No you can''t create a single reusable trigger and from what you describe it wouldn''t work anyway. You need to create a trigger for each table, user and admin, and have it do the insert into typeref table.


这篇关于是否有可能创建一个作用于2个表的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆