Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL server Newbie question about specific trigger

Author  Topic 

hgoodric
Starting Member

1 Post

Posted - 2014-07-01 : 11:55:12
I have a table called K2K01.dbo.cust

and another called K2KConceptActions.dbo.Actions(different database, same server)

The K2K01.dbo.cust table is part of an ERP system.

The K2KConceptActions.dbo.Actions table is a queuing table for a .net based web service and client app that will reside on the server and monitor the K2KConceptActions.dbo.Actions for updated and inserted records and then connect to another server via its web service (hence client app) and deliver a payload of updated or new data.

The K2KConceptActions.dbo.Actions table is traffic central for .net app to monitor inserts and updates for the customer master (K2K##.dbo.cust) and item master tables (K2K##.dbo.item) across 4 databases (K2K01, K2K02, K2K03, K2K04)

SO, what is inserted into the K2KConceptActions.dbo.Actions table is: (these are the columns)

Action - UPDATE or INSERT

Database - which db the change came from

Source - CustomerMaster or ItemMaster

KeyData - the key that the .net app will look up the record out of the database and table


Also there is an INT incrementor column called "UID"

I need help writing the first trigger. I can get the rest once I see how to write the first one.

So assuming the first trigger is an AFTER trigger on the insert of a new customer master record or multiple inserts within the transaction,my pseudo code for the trigger would be:




Create the trigger K2K01.dbo.InsertCustomerInsertAction on K2K01.dbo.cust

FOR INSERT

BEGIN

IF @@rowcount = 0 RETURN


for each record inserted into (call the record I) ,

create a record in such that:

M2MConceptActions.dbo.Actions.Action ="INSERT"

M2MConceptActions.dbo.Actions.Database="K2K01"

M2MConceptActions.dbo.Actions.source = "CustomerMaster "
M2MConceptActions.dbo.Actions.KeyData= i.CustomerID

Any help would be appreciated!

Thnx!!
Harold G


























   

- Advertisement -