dbTalk Databases Forums  

Trigger Question

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Trigger Question in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mike
 
Posts: n/a

Default Trigger Question - 04-21-2006 , 10:58 AM






I have a SQL based ERP package. Now I am having an issue on a
particular table of people deleting a record (in the ERP system) and no
one having any idea of who did it or when.

So I thought I would setup a delete trigger so that when a record is
deleted from a table it would populate a new table that I created with
some information, doc_no, date etc... My problem is how can I get the
new table to populate only information for the record being deleted.

I did one try and it populated it with all remaining records. Ok I see
my logic error, but realized that I don't know how or if I can populate
it with info from the record being deleted.

Thanks in advance.


Reply With Quote
  #2  
Old   
MGFoster
 
Posts: n/a

Default Re: Trigger Question - 04-21-2006 , 01:31 PM






mike wrote:
Quote:
I have a SQL based ERP package. Now I am having an issue on a
particular table of people deleting a record (in the ERP system) and no
one having any idea of who did it or when.

So I thought I would setup a delete trigger so that when a record is
deleted from a table it would populate a new table that I created with
some information, doc_no, date etc... My problem is how can I get the
new table to populate only information for the record being deleted.

I did one try and it populated it with all remaining records. Ok I see
my logic error, but realized that I don't know how or if I can populate
it with info from the record being deleted.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Have you tried the deleted derived table?

CREATE TRIGGER WhoDeleted
ON erp_table FOR DELETE
AS
INSERT INTO audit_table (user_name, doc_no, delete_date)
SELECT CURRENT_USER, doc_no, CURRENT_TIMESTAMP
FROM deleted
GO
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBREkk74echKqOuFEgEQJupgCfUIt6dnQ/LIU5IKEZVwQXtnCCmwAAoLG8
QbqJCqJGaxnk7MbuUesxJlXt
=eI+m
-----END PGP SIGNATURE-----


Reply With Quote
  #3  
Old   
mike
 
Posts: n/a

Default Re: Trigger Question - 04-21-2006 , 02:13 PM



Ah, that did it. Just never saw the "From Deleted " before.
Thanks..


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.