Solved

Inserted vs Deleted Table?

Posted on 2013-06-13
2
290 Views
Last Modified: 2013-06-14
I'm looking to have a records sent to a history table. I would like to have a trigger that works when i delete or update any attribute within my table.
When i DELETE a record, should i be pulling that from the temp (Inserted or Deleted table).
Should these be seperate Triggers one for Update and one for Delete?
I'm just wanting to understand these correctly.
Will this work?
ALTER TRIGGER [dbo].[Changes_Segment] 
ON  [dbo].[Segment]
FOR UPDATE, Delete 
AS 

IF UPDATE(L_F_ADD) 
OR UPDATE(L_T_ADD) 
OR UPDATE(R_T_ADD)
OR UPDATE(R_F_ADD) 
OR UPDATE(ROADJUR)
    INSERT INTO dbo.Segment_History
    SELECT * FROM inserted

Open in new window

Thanks
0
Comment
Question by:PtboGiser
2 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39245816
for your requirement you have to pull it form the deleted table

simple thumb rule

inserted table always holds the new data (i.e. the data that will be there after update / insert)
Deleted table always holds the old data (i.e. the data that will be deleted / updated).

I hope this helps.

Thanks
surendra
0
 

Author Comment

by:PtboGiser
ID: 39247466
Pulling from 2 different tables should be done in 2 different Triggers correct?
As a general rule.
Thanks i was reading similar stuff online but really wanted to confirm it!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL that will turn the rows in to columnsin date format 28 52
Using this function 4 38
removing unwanted rows from an sql server ranked table 13 34
SQL Syntax 6 26
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.
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…
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

679 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