使用一个触发器,只是添加时才触发,目的为了限制ip三分钟发送一条短信,这个表某一段时间内访问频率非常之高,今天高峰时出现了死锁的情况
可能是因为没有判断用户的原因,现在加上用户判断再观察一下,代码大概如下:
ALTER
trigger
[
dbo
].
[
trg_drv_yzm_insert
]
on
[
dbo
].
[
drv_yzm
]
for
insert
as
begin
if ( CURRENT_USER = ' testuser ')
begin
declare @lastcreatet varchar( 50)
declare @lastdate datetime
declare @id int, @clientip varchar( 15), @type varchar( 20)
select @id =id, @clientip =clientip, @type =type from inserted;
select top 1 @lastcreatet =createt from drv_yzm where clientip = @clientip and type = ' pre ' and id <> @id order by createt desc
set @lastdate = convert( datetime, substring( left( @lastcreatet, 8) + ' ' + substring( @lastcreatet, 9, 2) + ' : ' + substring( @lastcreatet, 11, 2) + ' : ' + substring( @lastcreatet, 13, 2), 1, 17))
set @lastdate = dateadd(mi, 3, @lastdate)
if( @lastdate > GETDATE() and @type = ' pre ')
update drv_yzm set status = ' 0 ' where id = @id
end
end
as
begin
if ( CURRENT_USER = ' testuser ')
begin
declare @lastcreatet varchar( 50)
declare @lastdate datetime
declare @id int, @clientip varchar( 15), @type varchar( 20)
select @id =id, @clientip =clientip, @type =type from inserted;
select top 1 @lastcreatet =createt from drv_yzm where clientip = @clientip and type = ' pre ' and id <> @id order by createt desc
set @lastdate = convert( datetime, substring( left( @lastcreatet, 8) + ' ' + substring( @lastcreatet, 9, 2) + ' : ' + substring( @lastcreatet, 11, 2) + ' : ' + substring( @lastcreatet, 13, 2), 1, 17))
set @lastdate = dateadd(mi, 3, @lastdate)
if( @lastdate > GETDATE() and @type = ' pre ')
update drv_yzm set status = ' 0 ' where id = @id
end
end