Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

10774: trigger DML o insert

Posted on 2014-10-17
1
Medium Priority
?
276 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

721 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