sql Server 大量数据批量插入 并发 死锁 情况怎么解决啊 这个存储过程能否优化
以下 是存储过程,
其中 Tweeter,Tweets,TweetsCount都存在大量数据,最低千万级的
加了 nolock不行,大家还有什么好的解决办法啊
其中 Tweeter,Tweets,TweetsCount都存在大量数据,最低千万级的
加了 nolock不行,大家还有什么好的解决办法啊
ALTER PROC [dbo].[TweetsAddOrUpdate]
@WebSiteId int,
@TweeterId bigint,
@WebTweetsId nvarchar(50),
@SourceId bigint,
@WebSourceId nvarchar(50),
@Content nvarchar(4000),
@CutWordStatus bit,
@OriginalText nvarchar(4000),
@ForwardCount int,
@CommentCount int,
@TweeterPostType nvarchar(100),
@TweeterPostTime datetime,
@TweetsType int,
@Location nvarchar(50),
@UpdateTime datetime,
@TweetsImportance int,
@ProvinceName nvarchar(50),
@CityName nvarchar(50)
as
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION
declare @ProvinceId int
declare @cityId int
select @ProvinceId=CityId from City(nolock) where Name=@ProvinceName
select @cityId=CityId from City(nolock) where Name=@CityName and ParentId=@ProvinceId
DECLARE @TweetsId bigint
IF not exists (select TweetsId from Tweets(nolock) where WebTweetsId=@WebTweetsId and WebSiteId=@WebSiteId)
begin
INSERT INTO [Tweets]
([WebSiteId],[TweeterId],[WebTweetsId],[SourceId]
,[WebSourceId],[Content],[OriginalText]
,[ForwardCount],[CommentCount],[TweeterPostType]
,[TweeterPostTime],[TweetsType],[Location]
,[UpdateTime],TweetsImportance,ProvinceId,CityId)
VALUES
(@WebSiteId,@TweeterId,@WebTweetsId,@SourceId
,@WebSourceId,@Content,@OriginalText
,@ForwardCount,@CommentCount,@TweeterPostType
,@TweeterPostTime,@TweetsType,@Location
,getDate(),@TweetsImportance,@ProvinceId,@cityId)
SET @TweetsId=@@identity
end
else
begin
select @TweetsId=TweetsId from Tweets(nolock) where WebTweetsId=@WebTweetsId and WebSiteId=@WebSiteId
update Tweets set ForwardCount=@ForwardCount,CommentCount=@CommentCount,
UpdateTime=getDate(),TweetsImportance=@TweetsImportance where TweetsId=@TweetsId
end
update Tweets set SourceId=@TweetsId where WebSourceId=@WebTweetsId
if exists (select TweetsId from TweetsCounts(nolock)
where TweetsId=@TweetsId and CONVERT(nvarchar(10),UpdateTime,112)
=cONVERT(nvarchar(10),GETDATE(),112)
)
begin
update TweetsCounts set ForwardCount=@ForwardCount,CommentCount=@CommentCount where
CONVERT(nvarchar(10),UpdateTime,112)
=cONVERT(nvarchar(10),GETDATE(),112)
and TweetsId=@TweetsId
end
else
begin
INSERT INTO [TweetsCounts]
([TweetsId]
,[ForwardCount]
,[CommentCount]
,[UpdateTime])
VALUES
(@TweetsId,@ForwardCount,@CommentCount,GETDATE())
end
select @TweetsId
COMMIT TRANSACTION
...全文
相关推荐
SQL Server死锁查询
日常SQL Server出现事物锁表,查询锁表信息
SQL Server死锁的解除方法
SQL Server死锁使我们经常遇到的问题,下面就为您介绍如何查询SQL Server死锁,希望对您学习SQL Server死锁方面能有所帮助。
sql server 死锁检测
死锁的本质是一种僵持状态,是多个主体对于资源的争用而导致的。理解死锁首先需要对死锁所涉及的相关观念有一个理解。
SQL Server死锁产生的原因及解决办法
本文举例说明SQL Server死锁产生的原因,并提出了解决的办法。
查询SQL server数据库死锁存储过程
查询SQL server数据库死锁存储过程


