MySQL Forums
Forum List  »  Triggers

Would a function or procedure work in my case? Executed by a trigger?
Posted by: Jim Schwartz
Date: January 03, 2021 02:29PM

I have six tables:

SALES
S000
S001
S002
S003
S004

I want to create a trigger so that, when a new record is inserted to any of the tables S000...S004, the field SALES.LAST_DATE in a specific record is updated with the value of the field "SALE_DATE" that was just inserted (in S000...s004).

Here is pseudo-code:

---------------------
if table(S000...S004) has a new record inserted then
x = tablename that was just updated
y = SALE_DATE from record that was just inserted
update SALES set LAST_DATE = y where TNAME = x
end if
---------------------

"TNAME" is a field in SALES that holds the tablename (S000...S004)

I've been working with MySQL for a while, but only simple tables and queries. I've never used triggers, functions or procedures.

Is this workable with a trigger, function or procedure?

BTW, I cannot change the design of the tables, because some old programs rely on the table structure just the way it is.

Any advice, suggestions or insights is appreciated in advance! Or even just pointing me in the right direction.

Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
Would a function or procedure work in my case? Executed by a trigger?
664
January 03, 2021 02:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.