Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Inserted vs Deleted Table?

Posted on 2013-06-13
2
Medium Priority
?
296 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

916 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