Friday, March 30, 2012

Problem in instead of trigger

hi,
i am using instead of trigger in sqlserver 2005, my trigger looks like
create trigger [dbo].[docsUpdate]
on [dbo].[Docs]
instead of update
as
IF (Update(MetaInfo))
BEGIN
bla bla
bla bla
[Some operation]
end
my table looks lke this
Dirname LeafName TimeLastModified Extension Metainfo
-- -- -- -- --
if any data in metainfo column updated then my trigger will get fired
and do respective operation, but when dirname , leafname or any if
other column get modified other them metainfo then how these modified
data will get affected in to my docs table.
Since changes done on table will not get affected due to instead of
trigger, how can i update other column values.
please help me.
thanks
sathya narayanan
narayanan@.gsdindia.comhttp://www.microsoft.com/communitie...c7-cdfb17b609f8
AMB
"sathya" wrote:

> hi,
>
> i am using instead of trigger in sqlserver 2005, my trigger looks like
>
> create trigger [dbo].[docsUpdate]
> on [dbo].[Docs]
> instead of update
> as
> IF (Update(MetaInfo))
> BEGIN
> bla bla
> bla bla
> [Some operation]
> end
> my table looks lke this
>
> Dirname LeafName TimeLastModified Extension Metainfo
> -- -- -- -- --
>
> if any data in metainfo column updated then my trigger will get fired
> and do respective operation, but when dirname , leafname or any if
> other column get modified other them metainfo then how these modified
> data will get affected in to my docs table.
> Since changes done on table will not get affected due to instead of
> trigger, how can i update other column values.
> please help me.
>
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>sql

problem in instead of Trigger

hi,
i am using trigger as below:
alter TRIGGER Docsdelete
ON Docs
INSTEAD OF DELETE
AS
Declare @.DeletedDocLibRowId int
declare @.Dirname nvarchar(256)
declare @.LeafName nvarchar(128)
set @.Dirname = (SELECT dirname FROM DELETED)
set @.LeafName = (SELECT leafname FROM DELETED)
set @.DeletedDocLibRowId = (SELECT doclibrowid FROM DELETED)
if(@.DeletedDocLibRowId IS NULL)
BEGIN
DELETE docs from deleted where docs.dirname = @.Dirname and
docs.leafname = @.LeafName
END
my problem is that i want to delete row in instead of trigger method,
but when i use this method, i cannot delete my row , the row seems to
be still in table even when i apply my trigger.
please anyone help me in this regard.
sathya naryanan v
narayanan@.gsdindia.comThat a often misunderstanding of triggers.
Trigers are fired per DML Operation rather than per row, so the statement
> DELETE docs from deleted where docs.dirname = @.Dirname and
> docs.leafname = @.LeafName
wont work because if you delete more than one row it will Rollback end with
an error.

> alter TRIGGER Docsdelete
> ON Docs
> INSTEAD OF DELETE
> AS
> Declare @.DeletedDocLibRowId int
> declare @.Dirname nvarchar(256)
> declare @.LeafName nvarchar(128)
> set @.Dirname = (SELECT dirname FROM DELETED)
> set @.LeafName = (SELECT leafname FROM DELETED)
> set @.DeletedDocLibRowId = (SELECT doclibrowid FROM DELETED)

> if (Select COUNT(*) from deleted where DeletedDocLibRowId IS NOT NULL) > 0
> BEGIN
Delete From sometable s--That table you want to delete from
inner join deleted d
on
s.dirname = d.dirname AND
d.leafname = d.leafname
> END
HTH, Jens Suessmeyer.
"sathya" <sathyanarayananit@.gmail.com> wrote in message
news:1122111997.898569.102710@.g43g2000cwa.googlegroups.com...
> hi,
> i am using trigger as below:
> alter TRIGGER Docsdelete
> ON Docs
> INSTEAD OF DELETE
> AS
> Declare @.DeletedDocLibRowId int
> declare @.Dirname nvarchar(256)
> declare @.LeafName nvarchar(128)
> set @.Dirname = (SELECT dirname FROM DELETED)
> set @.LeafName = (SELECT leafname FROM DELETED)
> set @.DeletedDocLibRowId = (SELECT doclibrowid FROM DELETED)
> if(@.DeletedDocLibRowId IS NULL)
> BEGIN
> DELETE docs from deleted where docs.dirname = @.Dirname and
> docs.leafname = @.LeafName
> END
> my problem is that i want to delete row in instead of trigger method,
> but when i use this method, i cannot delete my row , the row seems to
> be still in table even when i apply my trigger.
> please anyone help me in this regard.
>
> sathya naryanan v
> narayanan@.gsdindia.com
>|||On 23 Jul 2005 02:46:37 -0700, sathya wrote:

>hi,
>i am using trigger as below:
>alter TRIGGER Docsdelete
>ON Docs
>INSTEAD OF DELETE
>AS
>Declare @.DeletedDocLibRowId int
>declare @.Dirname nvarchar(256)
>declare @.LeafName nvarchar(128)
>set @.Dirname = (SELECT dirname FROM DELETED)
>set @.LeafName = (SELECT leafname FROM DELETED)
>set @.DeletedDocLibRowId = (SELECT doclibrowid FROM DELETED)
>if(@.DeletedDocLibRowId IS NULL)
>BEGIN
>DELETE docs from deleted where docs.dirname = @.Dirname and
>docs.leafname = @.LeafName
>END
>my problem is that i want to delete row in instead of trigger method,
>but when i use this method, i cannot delete my row , the row seems to
>be still in table even when i apply my trigger.
>please anyone help me in this regard.
Hi sathya,
Jens is correct that this trigger will only work for single-row deletes.
However, if you tested it with single-row deletes, I see no reason why
it would not work. Visual review of the code leads me to believe that
the row will actually be deleted if doclibrowid in the row is NULL, and
it will not be deleted if doclibrowid is anything but NULL.
That being said, it is unneeded to use the "from deleted" in the final
DELETE statement. Remove it, to save SQL Server some extra work.
And when you're busy changing things, why not go ahead and make it
multi-row proof as well. I believe that Jens missed the requirement for
doclibrowid to be NULL, so I'll show you another version. It differs
from Jens' version in two regards: it tests for doclibrowid to be NULL,
and it uses the more standard ANSI-standard DELETE FROM syntax instead
of the proprietary Transact-SQL DELETE FROM FROM syntax.
ALTER TRIGGER Docsdelete
ON docs
INSTEAD OF DELETE
AS
DELETE FROM docs
WHERE EXISTS (SELECT *
FROM deleted
WHERE deleted.dirname = docs.dirname
AND deleted.leafname = docs.leafname
AND deleted.doclibrowid IS NULL)
(untested)
If this still doesn't work, then consider:
a) using an AFTER trigger to rollback unwanted changes instead of using
an INSTEAD OF trigger to execute only the wanted changes - in my
experience, AFTER triggers often prove easier to understand and to
handle.
or
b) post a script that includes CREATE TABLE statements and INSERT
statements so that we can reproduce what you are experiencing. Add the
expected output to your script. See www.aspfaq.com/5006 for more
details.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Problem in instead of trigger

hi,
i am using instead of trigger in sqlserver 2005, my trigger looks like
create trigger [dbo].[docsUpdate]
on [dbo].[Docs]
instead of update
as
IF (Update(MetaInfo))
BEGIN
bla bla
bla bla
[Some operation]
end
my table looks lke this
Dirname LeafName TimeLastModified Extension Metainfo
-- -- -- -- --
if any data in metainfo column updated then my trigger will get fired
and do respective operation, but when dirname , leafname or any if
other column get modified other them metainfo then how these modified
data will get affected in to my docs table.
Since changes done on table will not get affected due to instead of
trigger, how can i update other column values.
please help me.
thanks
sathya narayanan
narayanan@.gsdindia.com
http://www.microsoft.com/communities...7-cdfb17b609f8
AMB
"sathya" wrote:

> hi,
>
> i am using instead of trigger in sqlserver 2005, my trigger looks like
>
> create trigger [dbo].[docsUpdate]
> on [dbo].[Docs]
> instead of update
> as
> IF (Update(MetaInfo))
> BEGIN
> bla bla
> bla bla
> [Some operation]
> end
> my table looks lke this
>
> Dirname LeafName TimeLastModified Extension Metainfo
> -- -- -- -- --
>
> if any data in metainfo column updated then my trigger will get fired
> and do respective operation, but when dirname , leafname or any if
> other column get modified other them metainfo then how these modified
> data will get affected in to my docs table.
> Since changes done on table will not get affected due to instead of
> trigger, how can i update other column values.
> please help me.
>
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>

Problem in instead of trigger

hi,
i am using instead of trigger in sqlserver 2005, my trigger looks like
create trigger [dbo].[docsUpdate]
on [dbo].[Docs]
instead of update
as
IF (Update(MetaInfo))
BEGIN
bla bla
bla bla
[Some operation]
end
my table looks lke this
Dirname LeafName TimeLastModified Extension Metainfo
-- -- -- -- --
if any data in metainfo column updated then my trigger will get fired
and do respective operation, but when dirname , leafname or any if
other column get modified other them metainfo then how these modified
data will get affected in to my docs table.
Since changes done on table will not get affected due to instead of
trigger, how can i update other column values.
please help me.
thanks
sathya narayanan
narayanan@.gsdindia.comhttp://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sqlserver.programming&mid=2144dbff-77b7-4327-b3c7-cdfb17b609f8
AMB
"sathya" wrote:
> hi,
>
> i am using instead of trigger in sqlserver 2005, my trigger looks like
>
> create trigger [dbo].[docsUpdate]
> on [dbo].[Docs]
> instead of update
> as
> IF (Update(MetaInfo))
> BEGIN
> bla bla
> bla bla
> [Some operation]
> end
> my table looks lke this
>
> Dirname LeafName TimeLastModified Extension Metainfo
> -- -- -- -- --
>
> if any data in metainfo column updated then my trigger will get fired
> and do respective operation, but when dirname , leafname or any if
> other column get modified other them metainfo then how these modified
> data will get affected in to my docs table.
> Since changes done on table will not get affected due to instead of
> trigger, how can i update other column values.
> please help me.
>
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>

Problem in Instead of Delete Trigger

Hi,
I have Instead of Delete Trigger in my Table. When i delete any row
from the table it shows the No of Rows affected ex:- 1 Row affected
But when i look into the table the Deleted Row is still Present.
My Question is If there is Instead of Delete Trigger then is it not
possible to delete row from Original table. and if i want to delete the
row using Instead of trigger what i have to do?
If anybody knows the solution Please let me know?
Thanks,
Vinoth
It really depends on what are you doing in the instead of delete trigger. Do
you actually delete the row in the trigger? Please post sample code from the
trigger if you need more help (desired result and sample data/table would be
helpful...)
MC
<vinoth@.gsdindia.com> wrote in message
news:1132308519.761801.276040@.g49g2000cwa.googlegr oups.com...
> Hi,
> I have Instead of Delete Trigger in my Table. When i delete any row
> from the table it shows the No of Rows affected ex:- 1 Row affected
> But when i look into the table the Deleted Row is still Present.
> My Question is If there is Instead of Delete Trigger then is it not
> possible to delete row from Original table. and if i want to delete the
> row using Instead of trigger what i have to do?
> If anybody knows the solution Please let me know?
>
> Thanks,
> Vinoth
>
|||Hi,
if I understand you correct you're deleteing a record and your trigger is
firing reporting the number of rows affected ? So far so good. If this
was
a normal "After" trigger the record would be deleted in the table. An
instead of trigger is different. The delete actually take place in the
table. You have to do that by yourself.
So in your trigger code you could do something like this :
Delete from table where id=(Select id from deleted)
But why are you using an instead of trigger and not an after trigger ?
Normally you use instead of triggers when you want to handle the dml
action
yourself for instance in partitioned views.
Regards
Bobby Henningsen
"MC" <marko_culo#@.#yahoo#.#com#> wrote in message
news:eHrFsqC7FHA.476@.TK2MSFTNGP15.phx.gbl...
> It really depends on what are you doing in the instead of delete
trigger.
> Do you actually delete the row in the trigger? Please post sample code
> from the trigger if you need more help (desired result and sample
> data/table would be helpful...)
>
> MC
>
> <vinoth@.gsdindia.com> wrote in message
> news:1132308519.761801.276040@.g49g2000cwa.googlegr oups.com...
>
Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at f? 711 spam-mails.
Betalende brugere f?r ikke denne besked i deres e-mails.
Hent gratis SPAMfighter her: www.spamfighter.dk

Problem in Instead of Delete Trigger

Hi,
I have Instead of Delete Trigger in my Table. When i delete any row
from the table it shows the No of Rows affected ex:- 1 Row affected
But when i look into the table the Deleted Row is still Present.
My Question is If there is Instead of Delete Trigger then is it not
possible to delete row from Original table. and if i want to delete the
row using Instead of trigger what i have to do?
If anybody knows the solution Please let me know?
Thanks,
VinothIt really depends on what are you doing in the instead of delete trigger. Do
you actually delete the row in the trigger? Please post sample code from the
trigger if you need more help (desired result and sample data/table would be
helpful...)
MC
<vinoth@.gsdindia.com> wrote in message
news:1132308519.761801.276040@.g49g2000cwa.googlegroups.com...
> Hi,
> I have Instead of Delete Trigger in my Table. When i delete any row
> from the table it shows the No of Rows affected ex:- 1 Row affected
> But when i look into the table the Deleted Row is still Present.
> My Question is If there is Instead of Delete Trigger then is it not
> possible to delete row from Original table. and if i want to delete the
> row using Instead of trigger what i have to do?
> If anybody knows the solution Please let me know?
>
> Thanks,
> Vinoth
>|||Hi,
if I understand you correct you're deleteing a record and your trigger is
firing reporting the number of rows affected ' So far so good. If this
was
a normal "After" trigger the record would be deleted in the table. An
instead of trigger is different. The delete actually take place in the
table. You have to do that by yourself.
So in your trigger code you could do something like this :
Delete from table where id=(Select id from deleted)
But why are you using an instead of trigger and not an after trigger ?
Normally you use instead of triggers when you want to handle the dml
action
yourself for instance in partitioned views.
Regards :)
Bobby Henningsen
"MC" <marko_culo#@.#yahoo#.#com#> wrote in message
news:eHrFsqC7FHA.476@.TK2MSFTNGP15.phx.gbl...
> It really depends on what are you doing in the instead of delete
trigger.
> Do you actually delete the row in the trigger? Please post sample code
> from the trigger if you need more help (desired result and sample
> data/table would be helpful...)
>
> MC
>
> <vinoth@.gsdindia.com> wrote in message
> news:1132308519.761801.276040@.g49g2000cwa.googlegroups.com...
>> Hi,
>> I have Instead of Delete Trigger in my Table. When i delete any row
>> from the table it shows the No of Rows affected ex:- 1 Row affected
>> But when i look into the table the Deleted Row is still Present.
>> My Question is If there is Instead of Delete Trigger then is it not
>> possible to delete row from Original table. and if i want to delete the
>> row using Instead of trigger what i have to do?
>> If anybody knows the solution Please let me know?
>>
>> Thanks,
>> Vinoth
>
---
Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at få 711 spam-mails.
Betalende brugere får ikke denne besked i deres e-mails.
Hent gratis SPAMfighter her: www.spamfighter.dksql

Problem in Instead of Delete Trigger

Hi,
I have Instead of Delete Trigger in my Table. When i delete any row
from the table it shows the No of Rows affected ex:- 1 Row affected
But when i look into the table the Deleted Row is still Present.
My Question is If there is Instead of Delete Trigger then is it not
possible to delete row from Original table. and if i want to delete the
row using Instead of trigger what i have to do?
If anybody knows the solution Please let me know?
Thanks,
VinothHi ,
You cannot delete rows from a table which has a instead of delete trigger
configured.
Though, We can put delete statement for the table inside instead of trigger
but we need to keep RECURSIVE_TRIGGERS database option set correctly. This D
B
option will not cause trigger to fire again.
But still I am not sure why do you want to delete row from a trigger which
has instead of delete trigger configured.
--
Vishal Khajuria
9886170165
IBM Bangalore
"vinoth@.gsdindia.com" wrote:

> Hi,
> I have Instead of Delete Trigger in my Table. When i delete any row
> from the table it shows the No of Rows affected ex:- 1 Row affected
> But when i look into the table the Deleted Row is still Present.
> My Question is If there is Instead of Delete Trigger then is it not
> possible to delete row from Original table. and if i want to delete the
> row using Instead of trigger what i have to do?
> If anybody knows the solution Please let me know?
>
> Thanks,
> Vinoth
>