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.
Author |
Topic |
hgoodric
Starting Member
1 Post |
Posted - 2014-07-01 : 11:55:12
|
I have a table called K2K01.dbo.custand 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 INSERTDatabase - which db the change came fromSource - CustomerMaster or ItemMasterKeyData - the key that the .net app will look up the record out of the database and tableAlso 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.custFOR INSERTBEGINIF @@rowcount = 0 RETURNfor 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.CustomerIDAny help would be appreciated!Thnx!!Harold G |
|
|
|
|