是否有可能创建一个作用于2个表的触发器

编程入门 行业动态 更新时间:2024-10-21 13:27:08
本文介绍了是否有可能创建一个作用于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个表的触发器

本文发布于:2023-10-28 01:09:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有可能   触发器   创建一个   作用于

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!