Trigger for insert table
I have sql server 2005 and need to create trigger for insert query.
I have Table naemd as "Log" with column named as UserID,UserName,LogDate,LogTime and want to transfer data into other table named as "DataTable" with same column name.
I have created trigg开发者_JAVA技巧er
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[Transfer] on [dbo].[Log]
AFTER INSERT
AS
BEGIN
insert into DataTable (UserID,UserName,LogDate,LogTime)
SELECT UserID,UserName,LogDate,LogTime
FROM Log where UserID not in(select UserID from DataTable)
END
New Data is updated on daily basis in "Log" table and so i want to transfer new data from Log table to DataTable with trigger.Execution time is very high and so no output .
you have "inserted" table in trigger, so you can insert data from it
insert into DataTable (UserID, UserName, LogDate, LogTime)
select UserID, UserName, LogDate, LogTime
from inserted
In your trigger definition, you should be using the inserted
table, which contains all the rows added to the Log Table.
精彩评论