I Have a store procedure which could be simplified as:
INSERT into TABLE1 (column0, column1...)
SELECT field0, field1... from TABLE2
And I noticed sometime randomly the TABLE1 will miss SOME data from the insertion, what's the possibility to cause this problem? Isn't it automatically wrapped as 'Implicitly TRANSACTION'?
NOTE, that SP was called in a .NET C# code, and I didn't catch any exception during the execution when this weird issue happened.
[Edit0]: This is original sql statement in my production code:
CREATE PROCEDURE [dbo].[SaveSomething]
--The only parameter passed from C# code which is a XML format string.
@Source nvarchar(max)
AS
BEGIN
--Open that XML with a handle attached
EXEC sp_xml_preparedocument @docHandle OUTPUT, @Source
--turn that XML into a temp table
SELECT
[PeriodID]
,[DESCRIPTION]
...
INTO #tmpPeriods
FROM OPENXML(@docHandle, N'/FirstLevelRoot/SecondLevelRoot/LeafNode')
WITH (PeriodID nvarchar(10) '../@PromotionId',
[DESCRIPTION] nvarchar(60) '@Reason',
... )
--insert that temp table data to the real useful table. And this is the place we found randomly
--some condition satisfied rows in tmpPeriods didn't get inserted to TargetTable.
INSERT INTO [dbo].[TargetTable](
[ID]
,[DESCRIPTION]
...)
SELECT
SourceTable.[PeriodID]
,SourceTable.[DESCRIPTION]
...
FROM #tmpPeriods as SourceTable
LEFT JOIN [TargetTable]
ON SourceTable.[PeriodID] = TargetTable.ID
WHERE TargetTable.ID IS NULL
As my partner tested several times with the same input XML string, and have all tables emptied, but sometimes the TargetTable miss some expected rows.
The isolation level is the default of 'Read Committed'.