Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6977225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:35:55+00:00 2026-05-27T17:35:55+00:00

In DB2 for IBM System i I create this trigger for recording on MYLOGTABLE

  • 0

In DB2 for IBM System i I create this trigger for recording on MYLOGTABLE every insert operation made on MYCHECKEDTABLE:

SET SCHEMA MYSCHEMA;

CREATE TRIGGER MYTRIGGER AFTER INSERT ON MYCHECKEDTABLE
REFERENCING NEW AS ROWREF
FOR EACH ROW BEGIN ATOMIC
     INSERT INTO MYLOGTABLE -- after creation becomes MYSCHEMA.MYLOGTABLE
         (MMACOD, OPTYPE, OPDATE)
     VALUES (ROWREF.ID, 'I', CURRENT TIMESTAMP);
END;

The DBMS stores the trigger body with MYSCHEMA.MYLOGTABLE hardcoded.

Now imagine that we copy the entire schema as a new schema NEWSCHEMA. When I insert a record in NEWSCHEMA.MYCHECKEDTABLE a log record will be added to MYSCHEMA.MYLOGTABLE instead of NEWSCHEMA.MYLOGTABLE, i.e. in the schema where trigger and its table live. This is cause of big issues!! Also because many users can copy the schema without my control…

So, is there a way to specify, in the trigger body, the schema where the trigger lives? In this way we’ll write the log record in the correct MYLOGTABLE. Something like PARENT SCHEMA… Or is there a workaround?
Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:35:55+00:00Added an answer on May 27, 2026 at 5:35 pm

    Unfortunately I realized that the schema where a trigger lives can’t be detected from inside trigger’s body.

    But there are some workarounds (thanks to @krmilligan too):

    • Take away the user’s authority to execute CPYLIB and make them use a utility.
    • Create a background agent on the system that peridiocally runs looking for triggers that are out of synch.
    • For command CPYLIB set the default for TRG option to *NO. In this way triggers will never be copied, except if the user explicitly specifies it.

    I choose the last one because it’s the simplest one, even if there can be contexts where trigger copy is required. In such cases I’d take the first workaround.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was getting this error com.ibm.db2.jcc.b.SqlException: Invalid argument: unknown column name COL1 when trying
I have a set of files in a library on an AS/400/iSeries/System-I/whatever-IBM-wants-me-to-call-it-these-days which I
I'm trying to dump the contents of a particular schema in one IBM DB2
I used this question/answer to install DB2 in Lion: How do I install IBM
I'm getting this exception: com.ibm.db2.jcc.c.SqlException: The syntax of the string representation of a datetime
I have written a DB2 query to do the following: Create a temp table
I'm having issues with getting DBI's IBM DB2 driver to work with mod_perl. My
I’m working on tuning and increasing the performance of my IBM DB2 version 9.7
Can any one give me the syntax to truncate a table in IBM DB2.
I am using IBM DB2 V 9.1.0.356. I am using DB2 JDBC driver version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.