Is there any method in Triggers to skip update/insert from particular user in DB2? - sql

I don't have much knowledge in TRIGGERS, below is my doubt kindly suggest any answers.
SYSTEM:
I have a table called A with Triggers, it designed in such a way if any update/insert happens it will update/insert the same in Table B.
PROCESS:
Table A will get updated by multiple users
MY QUESTION:
I want to block one user/Batch JOB. i.e. if any update/insert is performed by this user/BatchJob in TABLE A, it wont be propagated to Table B.
IS it possible in DB2 Triggers? If so Please Help me. Thanks in Advance!

You could add a new table to your DB that contains users you want to block (or add a column to an existing user table).
Then change your trigger like this
if current_user is not in blocked_user_table
then
insert in table b
end

Related

How can I solve this sql server scenario?

I do not know how to ask this question but my client asked me like this he wants for example he has a database at xxx.xxx.xxx.206 a table named Products but he also has a database at xxx.xxx.xxx.246and also a table called Products.
When he inserts a product at xxx.xxx.xxx.206 it should also be inserted inside Products table in xxx.xxx.xxx.246 automatically.
triggers came to my mind and I know how to make a trigger but... these kind of stuff he is asking is beyond my levels of knowledge using sql server.
How can I achieve such thing? Should I use triggers for this? but even using triggers how can I make that connection to another database?
Trigger can be a solution but when the destination is on another server it cause to reduce the performance.
I suggest you to create a job which transfer new inserted record to another server. Adding a new field is required to product table in xxx.xxx.xxx.206
Alter Table Products Add IsTransfered BIT Default(0)
I describe how to use this new filed in my answer to this question:
Identify new values in Table A and insert them in Table B

SQL Server : detect column changes

I am trying to detect any changes in a column. Let me describe my problem exactly.
Let's say I have 400 stored procedures and 20 of them changes a column named ModDate in a table Users. But the ModDate column is not enough for me to achieve my goal. I need a dirty bit column let's say IsChanged.
My solution would be find and check the procedures that updates Users.ModDate and change these procedures to update IsChanged as well. But this is not efficient in time. Also, I may miss some procedures and this will cause problems.
So, my question; is it possible to alter a table/column to create an "on change" trigger? When any procedure changes the value of Users.ModDate, SQL Server will update the IsChanged column as 1 automatically.
Thanks for your answers.
You can create a trigger on a column for different crud events.
See https://www.sqlservertutorial.net/sql-server-triggers/sql-server-create-trigger/
`CREATE TRIGGER [schema_name.]trigger_name ON table_name AFTER {[INSERT],[UPDATE],[DELETE]} [NOT FOR REPLICATION] AS {sql_statements`}

PL/SQL Replicating a table with a trigger on Oracle DB

I have never used triggers in PLSQL before, but I am now supposed to make a trigger that replicates the table of one database, and creates a copy of this table in another database. I am using AQT(Advanced Query Tool) as DBMS, and i have 2 database connections, and I need to copy the table and or data from DB1 to DB2. It's only based on one table that I need replicated, following tutorialspoint I have concluded that it should look somewhat like this:
`
CREATE OR REPLACE TRIGGER db_transfer
AFTER DELETE OR INSERT OR UPDATE ON X
WHEN (NEW.ID > 0)
I don't think i need for each since i want a copy of the whole table, and the condition is supposed to trigger this replication of the DB table. Is this the right approach?
EDIT
For anyone who uses AQT, they have a feature under Create -> Trigger -> and then click on the relevant tables etc to create it.

How to Create a single Trigger on multiple Database Tables

I have a database which contains some tables such as article, news, projects,...
I want to save a record to another table (Activity) when a record inserted into each table in database without activity
I don't want to create a trigger for each table.
How can I do it?
If you were to use an intermediate layer, such as an ORM like Entity Framework, you could, in effect, have a "database wide" trigger, by overriding the OnSaveChanges event to add a log record anytime something is committed to the database.
My answer on This Question does exactly that

Trigger when a select occurs

i have a customer with a ERP wich i don't have programming access, and wants to do a special trigger when a item is selected. The problem is that the ItemID is nowhere kept when chosen, only when whole sale is kept, and the trigger should happen before that.
This is a novice question for sure, but this value must be kept somewhere right ?
When i do a audit do see what happens when the item is chosen inside the ERP it only does SELECT statments. Can i do a trigger based on a SELECT ?
Thank you.
It is not possible to create a trigger based on execution of a select query in PL/SQL. Trigger can be created only on INSERT, UPDATE or DELETE.
References :
https://community.oracle.com/thread/1556647?tstart=0
http://www.geekinterview.com/question_details/18571