标签:des style color width os 2014
U872每月都需要做月结,对于制造企业来说,结算成本处理是必不可少的一个处理环节,每次查询出来待暂估记录也比较多(我接触到的有3万左右),暂估时间一般要2-3小时左右,若调用的大表索引碎片多时,会需要更长的时间,先看一下处理过程调用的主要步骤及脚本有哪些:<span style="font-size:12px;">Exec IA_WriSummary 按仓库核算,2,6, N'07', N'021299000098', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'',20,21.54,0,0,0,0</span>注:数量为正数
第一步:暂时禁用SQL代理中的一些计划任务,如备份、同步等
第二步:点【暂估】按钮前,一定要对rdrecords,Ia_Summary ,ia_subsidiary,PurBillVouchs,Inventory,Ia_Summary 重建或整理索引,索引碎片可以用dbo.fn_ShowIndexSP函数,重建索引可以用Dyl_ReindexNew过程
第三步:检查这些表的索引的碎片是否已全部在10以下,若是表示全部整理成功!
可以做结算成本处理的暂估操作了。
/*
功能:显示指定表的索引碎片
创建人:baronyang
创建时间:2014-07-02
select * from dbo.fn_ShowIndexSP('')
*/
Alter function dbo.fn_ShowIndexSP
(
@tablename varchar(255)
)
returns @table table (tablename varchar(255),indexname varchar(255),spbl int)
as
BEGIN
DECLARE @dbid int,@objid int
select @dbid=DB_ID(),@objid=OBJECT_ID(@tablename)
insert into @table (tablename,indexname,spbl)
SELECT c.name,b.name,avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL) as a
inner JOIN sys.indexes b on a.object_id=b.object_id and a.index_id=b.index_id
inner JOIN sys.objects c on a.object_id=c.object_id
where b.index_id>0 and avg_fragmentation_in_percent>=1
return
end/*
功能:重建整理
创建人:baronyang
创建时间:2014-07-02
exec Dyl_ReindexNew 'KQ_OtherData'
select * from dbo.fn_showindexsp('KQ_OtherData')
*/
Alter procedure dbo.Dyl_ReindexNew
@TableName varchar(255),
@indexname varchar(255)=''
as
set nocount on
declare @dbid int,@objid int,@sql varchar(1000)
select @dbid=DB_ID(),@objid=isnull(OBJECT_ID(@TableName),0)
if @objid=0
BEGIN
print @TableName+'表不存在'
return
End
IF Exists(SELECT * FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL)
where avg_fragmentation_in_percent>30 and index_id>0
) and @objid>0
BEGIN
set @sql='alter index '+case when isnull(@indexname,'')<>'' THEN @indexname else 'all' END
+' on '+@TableName+' rebuild WITH(online=on,STATISTICS_NORECOMPUTE=ON)'
exec (@SQL)
End
IF Exists(SELECT * FROM sys.dm_db_index_physical_stats(@dbid,@objid,NULL,NULL,NULL)
where avg_fragmentation_in_percent>30 and index_id>0 and @objid>0
)
print @TableName+'表索引碎片还是超过30,请手动重建索引'
U872-结算成本处理步骤及索引处理,布布扣,bubuko.com
标签:des style color width os 2014
原文地址:http://blog.csdn.net/baronyang/article/details/36180705