我有一个 Sql 过程,它从表中选择记录,如果它匹配插入到不同的表。如下
CREATE PROCEDURE [dbo].[MarkCopyData]
@copyDataOperationId int,
@countryCode nvarchar(50),
@batchCount int,@batchId int,@jobId int
AS
BEGIN
DECLARE @TableObjectId AS Int;
SET @TableObjectId = OBJECT_ID('Table1');
INSERT INTO
Table2(
TableObjectId,
SourcePrimaryKey,
DestinationCopyOperationId,
IsModifiedAftertCopied,IsDeleted,BatchId,JobId)
SELECT TOP (@batchCount) @TableObjectId, tbl1.pkid, @copyDataOperationId, 0,0,@batchId,@jobId
FROM [dbo].[Table1] AS tbl1
Inner join [dbo].[Country] AS C on C.CountryId = tbl1.fkid
LEFT OUTER JOIN Table2 tbl2 on (tbl2 .SourcePrimaryKey = tbl1.pkid and tbl2 .TableObjectId = @TableObjectId)
WHERE C.CountryCode = @countryCode AND tbl2.DestinationCopyOperationId IS NULL
SELECT @@ROWCOUNT
END
GO
任何人都可以请提出提示以提高此过程的性能