Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, April 20, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: Update Trigger On Address Table
Yup.
Posts: 126
 
Update Trigger On Address TableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Sep 10 8:59 AM
There is currently an update trigger on the address table that updates the corresponding address in our ERP system. This trigger frequently appears in my profile traces for long running queries, and as such, I am looking to increase the performance of the trigger. When I run a simple update on the address table in QA (SS2k), ~92% of the cost takes place when "scanning the pseudo-table for "inserted" within a trigger." I will post the contents of the trigger below. Does anyone have any thoughts on how to improve the performance of this? My initial thought is to make the trigger into one update statement, as opposed to checking for individual fields that may have been updated. Also, it was my understanding that SS is looking through the transaction logs when accessing "inserted," would it make more sense to insert the inserted row into a temp table or table variable, and then make the updates from there?




CREATE TRIGGER [tu_ADDRESS_TRIGGER] ON [sysdba].[ADDRESS]
FOR UPDATE

AS
If Exists(Select CUSTID from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID)
BEGIN
IF UPDATE(ADDRESS1)
Update MAS500_App.dbo.tciAddress set ADDRLINE1 = a.ADDRESS1
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID

IF UPDATE(ADDRESS2)
Update MAS500_App.dbo.tciAddress set ADDRLINE2 = a.ADDRESS2
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(ADDRESS3)
Update MAS500_App.dbo.tciAddress set ADDRLINE3 = a.ADDRESS3
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(ADDRESS4)
Update MAS500_App.dbo.tciAddress set ADDRLINE4 = a.ADDRESS4
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(CITY)
Update MAS500_App.dbo.tciAddress set CITY = a.CITY
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(STATE)
Update MAS500_App.dbo.tciAddress set STATEID = a.STATE
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(POSTALCODE)
Update MAS500_App.dbo.tciAddress set POSTALCODE = a.POSTALCODE
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID
IF UPDATE(COUNTRY)
Update MAS500_App.dbo.tciAddress set COUNTRYID = a.COUNTRY
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID

IF UPDATE(ADDRESS1) OR UPDATE(POSTALCODE) or UPDATE(ADDRESS2) or UPDATE(ADDRESS3) or UPDATE(CITY) or UPDATE(STATE)
Update MAS500_App.dbo.tciAddress set CRMADDRID = a.ADDRESSID
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID

END




[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Update Trigger On Address TableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Sep 10 9:40 AM
we do this based on the MODIFYDATE change, and then update all fields mapped in the other database....
[Reply][Quote]
Yup.
Posts: 126
 
Re: Update Trigger On Address TableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Sep 10 10:31 AM
This is what I have changed the trigger to,

If Exists(Select CUSTID from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID)
BEGIN
IF UPDATE(MODIFYDATE)
Update MAS500_App.dbo.tciAddress set ADDRLINE1 = a.ADDRESS1,
ADDRLINE2 = a.ADDRESS2,
ADDRLINE3 = a.ADDRESS3,
ADDRLINE4 = a.ADDRESS4,
CITY = a.CITY,
STATEID = a.STATE,
POSTALCODE = a.POSTALCODE,
COUNTRYID = a.COUNTRY,
CRMADDRID = a.ADDRESSID
from DL_Acct_Ref d,
Account c,
Address a,
MAS500_App.dbo.tarCustomer t,
MAS500_App.dbo.tciAddress i,
Inserted k
where d.Acct_ID = t.CustID
and t.dfltBilltoaddrkey = i.AddrKey
and d.AccountID = c.AccountID
and c.AddressID = a.AddressID
and t.CompanyID = 'QMC'
and a.ADDRESSID = k.ADDRESSID

END

The original trigger seemed ridiculous. If a city or state has been updated, then obviously the address information has also been updated.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 4/20/2024 10:57:29 AM