azure 获取仅100条记录的“执行超时已过期”错误

k5ifujac  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(175)

我有一个Azure Time Trigger函数,它的工作是从FTP读取Excel并将这些细节添加到数据库中。那个Excel大约有20K条记录,为了添加细节,我创建了一个使用MERGE查询进行插入和更新的存储过程。上周我收到以下错误"执行超时已过期“。在操作完成之前超时时间已过,或者服务器没有响应。操作被用户取消。语句已终止。等待操作超时。这是SP代码

CREATE PROCEDURE [dbo].[UploadStudents]
    @userUDT [dbo].[UserUDT] READONLY
AS  
BEGIN  
    UPDATE Students 
    SET IsActive = 0, IsDeleted = 1 

    MERGE Students AS Target
    USING @userUDT AS Source
    ON REPLACE(REPLACE(REPLACE(Source.email, CHAR(9), ''), CHAR(10), ''), CHAR(13), '') = REPLACE(REPLACE(REPLACE(Target.email, CHAR(9), ''), CHAR(10), ''), CHAR(13), '')

    -- For Inserts
    WHEN NOT MATCHED BY Target THEN
        INSERT (Id, CreatedOn, ModifiedOn, CreatedBy, IsActive, IsDeleted, Email, UserName, PrimaryIdentifier, SchoolDepartmentCode, UserGroup, UserRole, SpiceId) 
        VALUES (NEWID(), GETDATE(), GETDATE(), NULL, 1, 0, Source.Email, Source.[name], Source.PrimaryIdentifier, Source.SchoolDepartmentCode, Source.UserGroup, Source.[Role], Source.SpiceId)

    -- For Updates
    WHEN MATCHED THEN UPDATE 
        SET Target.UserName = Source.[Name],
            Target.PrimaryIdentifier = Source.PrimaryIdentifier,
            Target.SchoolDepartmentCode = Source.SchoolDepartmentCode,
            Target.UserGroup = Source.UserGroup,
            Target.UserRole = Source.[Role],
            Target.[IsActive] = 1,
            Target.[IsDeleted] = 0,
            Target.ModifiedOn = GETDATE();
END

为了解决这个问题,我已经添加了一个电子邮件列的索引,并创建了一批100条记录,并尝试调用SP,但仍然得到相同的超时错误。

lf3rwulv

lf3rwulv1#

通过在UDT表上添加主键(作为存储过程的输入)解决了问题

相关问题