Solved

10774: trigger DML o insert

Posted on 2014-10-17
1
274 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 66

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

626 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