Solved

mysql trigger refer to the "table name"

Posted on 2014-01-08
2
1,393 Views
Last Modified: 2014-01-08
Hello Experts,

Inside the code of the trigger, is it possible to get the name of the table that the trigger belongs to?

Something like "thistrigger.tablename" lol...

Thx in advanced
0
Comment
Question by:justaphase
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 39765975
Hi.

Triggers have a NEW and OLD to access columns of the inserted and deleted rows, respectively; however, it does not have a keyword for its own metadata as you showed.  To get information about trigger, you can query INFORMATION_SCHEMA.TRIGGERS.

For example:
SELECT EVENT_OBJECT_TABLE 
INTO @table_name
FROM INFORMATION_SCHEMA.TRIGGERS
WHERE TRIGGER_NAME = 'trigger name here'
;

Open in new window


Triggers are table-specific, so it is just as easy to hard-code the table name in the trigger body.  However, if the concern is that you may change the table name later, you can use the above query to dynamically find the table name.  Although, it also is vulnerable to trigger name changes.  Therefore, you will have to maintain the trigger body in either case.

I hope that helps.
0
 
LVL 1

Author Closing Comment

by:justaphase
ID: 39766774
Yes it helps!
I would prefer the table name, but since it's impossible, that's a good way to start.
It's more probable to change the table name, that is to change the trigger name.

Thx!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question