Solved

10774: trigger DML o insert

Posted on 2014-10-17
1
270 Views
Last Modified: 2014-10-17
Suppose I have the following procedure:

Create procedure PA_ActualizarTabla1
Campo_Nuevo Varchar (10)
as
Update Table1
September Field = @ Campo_Nuevo
where id = 1

I want to store in a table of audits before and after registration,
then my question is, which is faster ?,
Add 1 insert statements in this procedure to save the before and after in the table
2 Adding a DML trigger on that table
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40387383
For starters, your proc has an error, as the space in the name [September Field] forces the use of square brackets [] around the name.   Also there's a space after the @.

Not abundantly certain which is faster, but Adding a DML trigger would be the more accurate,

There may be better ways based on your audit table, but give this a whirl..
CREATE TRIGGER tg_upd_PA_ActualizarTabla1
AFTER UPDATE AS

Declare @dt datetime = GETDATE()

INSERT INTO your_audit_table (Col1, col2, col3, action, timestamp) 
SELECT col1, col2, col3, 'new', @dt
FROM inserted
UNION
SELECT col1, col2, col3, 'old', @dt
FROM deleted
GO

Open in new window

0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question