SQL Server After Insert Trigger not copying all rows
I have two tables in the same DB on SQL Server 2008. When I insert a row to the first I want some fields to be co开发者_运维问答pied to the second one. I made a trigger that is doing that but the problem is that sometimes when I add 2 rows very fast it is copying only one of them.
What is wrong with my code?
USE [DB_NAME]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[triggerName]
ON [dbo].[table1]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.table2(L_UID, L_Mode, C_Name, C_Logon)
SELECT ins.L_UID, ins.L_Mode, ins.C_Name, temp.C_Remark AS Logon FROM INSERTED AS ins
INNER JOIN dbo.tEmploye AS temp
ON (temp.L_UID = ins.L_UID)
WHERE temp.C_Remark IS NOT NULL
END
It almost certainly has nothing to do with "adding very fast". My best guess is that the rows your inserting don't always join with tEmploye. Try making it an outer join (if possible) and see if you continue to have these so-called missing rows, or if you get null in your C_Logon column in table2 (odd names for tables I must say --- such obfuscation makes figuring out a possible solution more difficult)
精彩评论