Re: Logging deletes...
From: Chris Marsh (cmarsh_at_synergy-intl.com)
Date: 11/12/04
- Next message: Carl Imthurn: "Re: Quick, simple crosstab question"
- Previous message: Adam Machanic: "Re: Quick, simple crosstab question"
- In reply to: Tom Moreau: "Re: Logging deletes..."
- Next in thread: Hugo Kornelis: "Re: Logging deletes..."
- Reply: Hugo Kornelis: "Re: Logging deletes..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 12 Nov 2004 12:43:18 -0500
Tom,
Thanks for the reply. I have tried the following without much success. On
both tables customer and delcustomer I have added a field called
"del_datetime" and then put in the default value "(getdate())" in hopes that
when the customer record is deleted, the trigger is fired and then the row
is added to the delcustomer table it would automatically add the datetime
value.
I am confident that if I get one of those values to update then I can add
the addtional values as well. Here is my current trigger:
_______________________
CREATE TRIGGER [SaveDeletedCustomer] ON [dbo].[customer]
INSTEAD OF DELETE -- Must use INSTEAD OF as the customer table has many Text
columns.
AS
--insert into delcustomer select * from deleted del --Save deleted record in
the Delcustomer table
INSERT INTO delcustomer
SELECT [cusid], ........ I deleted the other fields to make the email more
readable ....[pwd_key], [del_datetime]
FROM deleted del
DELETE customer FROM deleted where customer.cusid = deleted.cusid
_______________________
What am I doing wrong?
Thanks again.
Chris
"Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message
news:uaT%23P5MyEHA.924@TK2MSFTNGP10.phx.gbl...
> Check out CURRENT_USER and CURRENT_TIMESTAMP in the BOL.
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> .
> "Chris Marsh" <cmarsh@synergy-intl.com> wrote in message
> news:OsVx41MyEHA.2568@TK2MSFTNGP11.phx.gbl...
> So now I am cooking on my delete triggers; have them setup on about a
> dozen key tables and they are working like a champ! It would be really
> cool
> to
> know who has deleted the record and log that in the new Delxxxx table that
> I
> created (from the trigger). Or, is
> there another approach that is better?
>
> Any example on how I can log a users delete including the date and time
> within the trigger would be great. It
> would really be amazing if I even knew what PC they did it from?
>
> Each day I work with SQL 2000 I get more and more impressed by it's
> capabilities. I've spent the past 14 years in FoxPro data and there is
> just
> no comparison.
>
> Thanks again!
>
> Chris
>
>
- Next message: Carl Imthurn: "Re: Quick, simple crosstab question"
- Previous message: Adam Machanic: "Re: Quick, simple crosstab question"
- In reply to: Tom Moreau: "Re: Logging deletes..."
- Next in thread: Hugo Kornelis: "Re: Logging deletes..."
- Reply: Hugo Kornelis: "Re: Logging deletes..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|