I am using a simple trigger ins_process
for capturing inserts/updates on a table process
. This ins_process
inserts data into a table process_audit
.
process
has the following data originally inserted, in that order:
id name description
--- ---- -----------
1 proc1 sql
2 proc2 scripting
3 proc3 java
This creates the data in process_audit
as follows:
id name description insert_dt
--- ---- ----------- ---------
3 proc3 java [a minute ago]
2 proc2 scripting [a minute ago]
1 proc1 sql [a minute ago]
Why do the records get inserted in the reverse order?. When I edit a row from the front-end, the data in process_audit
is as follows:
id name description insert_dt
--- ---- ----------- ---------
3 proc3 java [a minute ago]
2 proc2 scripting [a minute ago]
1 proc1 sql [a minute ago]
2 proc2 scripting [now]
This is not so much of a problem for me. I am wondering if this is a standard behaviour or if there is something wrong in the way I have created the trigger.
Here is how I created the trigger:
create trigger [dbo].[ins_process]
on [dbo].[process] for insert, update
as
set nocount on
begin
insert into process_audit
(id, name, description, insertdate)
select
id, name, description,current_timestamp
from inserted ins
end
Also, the id
column in table process_audit
is not an Identity column.