Bom dia, a poucos dias notamos essa consulta com UPDATE e DELETE vindo da tabela history_store que faz parte do Protheus e também notamos uma Trigger que dispara ela e está travando demais nosso banco e ainda não conseguuimos distinguir exatamente o que ela faz e quando roda. Se alguém souber algo sobre isso e puder compartilhar agradeço.
Trigger
IF OBJECT_ID ('dbo.a_u_SC5010') IS NOT NULL DROP TRIGGER dbo.a_u_SC5010 GO
CREATE TRIGGER [a_u_SC5010] ON [dbo].[SC5010] FOR UPDATE AS BEGIN SET NOCOUNT ON;
DECLARE @time_mark DATETIME;DECLARE @tbl_name NVARCHAR(400);DECLARE @rec_state int;DECLARE @pk_d_old NVARCHAR(400);DECLARE @pk_d NVARCHAR(400);DECLARE @rs int;DECLARE @rcount int;
SET @time_mark = DATEADD(second, 0, getdate());SET @tbl_name = 'SC5010';SET @rec_state = 2;
SELECT @rcount = count(*) FROM inserted; If @rcount = 1 BEGIN SELECT @pkd_old = N'<R_E_C_N_O>'+CAST (deleted.[RE_C_N_O] AS NVARCHAR(400))+N'' FROM deleted; SELECT @pkd = N'<R_E_C_N_O>'+CAST (inserted.[RE_C_N_O] AS NVARCHAR(400))+N'' FROM inserted; SET @rs = 0; SELECT @rs = [recordstate] FROM [dbo].[history_store] WHERE [table_name] = @tbl_name AND [pk_date_src] = @pk_d_old; IF @rs = 0 INSERT INTO [dbo].history_store VALUES (@time_mark, @tbl_name, @pk_d,@pk_d_old, @rec_state ); ELSE UPDATE [dbo].[history_store] SET [timemark] = @time_mark, [pk_date_src] = @pk_d WHERE [table_name] = @tbl_name AND [pk_date_src] = @pk_d_old; END ELSE BEGIN UPDATE [dbo].[history_store] SET [timemark] = I.fTimeMark, [pk_date_src] = I.fValNew FROM ( SELECT @time_mark AS fTimeMark, N'<R_E_C_N_O>'+CAST (inserted.[RE_C_N_O] AS NVARCHAR(400))+N'' AS fValNew, N''+CAST (deleted.[RE_C_N_O] AS NVARCHAR(400))+N'' AS fValOld FROM deleted, inserted WHERE deleted.[RE_C_N_O] = inserted.[RE_C_N_O]) I WHERE [tablename] = @tbl_name AND [pk_date_src] = I.fValOld; INSERT INTO [dbo].history_store SELECT @time_mark, @tbl_name, N'<R_E_C_N_O>'+CAST (inserted.[RE_C_N_O] AS NVARCHAR(400))+N'', N''+CAST (deleted.[RE_C_N_O] AS NVARCHAR(400))+N'', @recstate FROM deleted, inserted WHERE deleted.[R_E_C_N_O] = inserted.[RE_C_N_O] AND N''+CAST (deleted.[RE_C_N_O] AS NVARCHAR(400))+N'' NOT IN (SELECT [pk_date_src] FROM [dbo].[history_store] WHERE [table_name] = @tbl_name); END END GO