Solved

Inserted vs Deleted Table?

Posted on 2013-06-13
2
289 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

789 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