Unix Technical Forum

table trigger just hangs

This is a discussion on table trigger just hangs within the SQL Server forums, part of the Microsoft SQL Server category; --> I have a UDF that cleans a field of control characters and I use it like this select dbo.udf_CleanAlphaNum(Address1) ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 05:08 PM
rcamarda
 
Posts: n/a
Default table trigger just hangs

I have a UDF that cleans a field of control characters and I use it
like this
select
dbo.udf_CleanAlphaNum(Address1) as Address1
from Leads

It works great. I use it to clean several fields from a vendors SQL
server. The downside is I have to first load the data into my database
so I can use my function to clean the data THEN proceed to load it
into the destination table. I thought I could create a trigger on the
final table that calls this function via a trigger.

This is my test CREATE TRIGGER

USE [Strayer_Staging]
GO
/****** Object: Trigger [dbo].[Clean_Q_Lead_Demographics] Script
Date: 04/16/2008 15:32:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE TRIGGER [dbo].[Clean_Q_Lead_Demographics]
ON [Strayer_Staging].[dbo].[Q_Lead_Demographics]
for update, insert
AS
update Strayer_Staging.dbo.Q_Lead_Demographics
set address1 = dbo.udf_CleanAlphaNum(inserted.Address1)
from INSERTED ;

when I try to update a record with

update q_lead_demographics
set address1 = '2 chestnut street'
where leadid = 1075789

it looks like it updates all records becuase it take 4 minutes and I
get this message:
(1055538 row(s) affected)

(1 row(s) affected)

it works, but on all rows, not just the updated row.

Is there a @@ variable that is the primary key so I should use a
WHERE, or am going about this all wrong?
TIA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 05:08 PM
rcamarda
 
Posts: n/a
Default Re: table trigger just hangs

On Apr 16, 3:32*pm, rcamarda <robert.a.cama...@gmail.com> wrote:
> I have a UDF that cleans a field of control characters and I use it
> like this
> select
> * dbo.udf_CleanAlphaNum(Address1) as Address1
> from *Leads
>
> It works great. I use it to clean several fields from a vendors SQL
> server. The downside is I have to first load the data into my database
> so I can use my function to clean the data THEN proceed to load it
> into the destination table. I thought I could create a trigger on the
> final table that calls this function via a trigger.
>
> This is my test CREATE TRIGGER
>
> USE [Strayer_Staging]
> GO
> /****** Object: *Trigger [dbo].[Clean_Q_Lead_Demographics] * *Script
> Date: 04/16/2008 15:32:15 ******/
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
>
> CREATE TRIGGER [dbo].[Clean_Q_Lead_Demographics]
> * *ON *[Strayer_Staging].[dbo].[Q_Lead_Demographics]
> * for update, insert
> AS
> * update Strayer_Staging.dbo.Q_Lead_Demographics
> * set address1 = dbo.udf_CleanAlphaNum(inserted.Address1)
> from INSERTED * ;
>
> when I try to update a record with
>
> update q_lead_demographics
> set address1 = '2 chestnut street'
> where leadid = 1075789
>
> it looks like it updates all records becuase it take 4 minutes and I
> get this message:
> (1055538 row(s) affected)
>
> (1 row(s) affected)
>
> it works, but on all rows, not just the updated row.
>
> Is there a @@ variable that is the primary key so I should use *a
> WHERE, or am going about this all wrong?
> TIA


This seems to work better the result shows I updated 2 records. Is it
becuase an update is really a delete and an update?

ALTER TRIGGER [dbo].[Clean_Q_Lead_Demographics]
ON [Strayer_Staging].[dbo].[Q_Lead_Demographics]
for update, insert
AS
update Strayer_Staging.dbo.Q_Lead_Demographics
set
address1 = dbo.udf_CleanAlphaNum(inserted.Address1),
address2 = dbo.udf_CleanAlphaNum(inserted.Address2),
address3 = dbo.udf_CleanAlphaNum(inserted.Address3),
bad_email = dbo.ValidateEmailAddress(lower(replace(inserted.em ail,'
',''))),
City = dbo.udf_CleanAlphaNum(inserted.City)
from inserted
where q_lead_demographics.leadid = inserted.leadid
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 05:08 PM
rcamarda
 
Posts: n/a
Default Re: table trigger just hangs

I got the trigger to work, but what added to my confusion was the bulk
load.
I was using the API method of bulk loading as provided in Cognos' Data
Manager ETL tool. I discovered that the trigger would work when I used
a normal relational delivery, but not the API bulk load.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 05:08 PM
Ed Murphy
 
Posts: n/a
Default Re: table trigger just hangs

rcamarda wrote:

> I got the trigger to work, but what added to my confusion was the bulk
> load.
> I was using the API method of bulk loading as provided in Cognos' Data
> Manager ETL tool. I discovered that the trigger would work when I used
> a normal relational delivery, but not the API bulk load.


http://msdn2.microsoft.com/en-us/library/ms171769.aspx indicates that
bulk loads ignore triggers unless called with FireTriggers = TRUE. Does
Data Manager have an option to activate that flag?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-29-2008, 09:26 PM
rcamarda
 
Posts: n/a
Default Re: table trigger just hangs

Turns out it doesnt.
I've submitted an enhancement request to Cognos about that aspect of
API loads and triggers.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:21 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com