手工重建重要的索引

2017/08/25 12:50:26
/*
说明:SQL Server有时候索引会损坏,引起紫日ERP运行特别慢。此语句用于手工修复重要的表索引
         该语句适于所有版本
*/


--尺码组资料
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DictSizeClassSet]') AND name = N'PK_DictSizeClassSet')
ALTER TABLE [dbo].[DictSizeClassSet] DROP CONSTRAINT [PK_DictSizeClassSet]
ALTER TABLE [dbo].[DictSizeClassSet] ADD  CONSTRAINT [PK_DictSizeClassSet] PRIMARY KEY CLUSTERED 
(
[cSizeclass] ASC,
[iSizePos] ASC
)WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DictSizeClassSet]') AND name = N'IX_DictSizeClassSet')
DROP INDEX [IX_DictSizeClassSet] ON [dbo].[DictSizeClassSet] WITH ( ONLINE = OFF )
CREATE NONCLUSTERED INDEX [IX_DictSizeClassSet] ON [dbo].[DictSizeClassSet] 
(
[cSizeName] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

--颜色资料
ALTER TABLE dbo.DictColor DROP CONSTRAINT PK_DictColor
ALTER TABLE dbo.DictColor ADD CONSTRAINT
PK_DictColor PRIMARY KEY CLUSTERED 
(
cColorCode
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

--商品资料
ALTER TABLE dbo.Inventory DROP CONSTRAINT PK_Inventory
ALTER TABLE dbo.Inventory ADD CONSTRAINT
PK_Inventory PRIMARY KEY CLUSTERED 
(
cInvCode
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

--渠道资料
ALTER TABLE dbo.Branch DROP CONSTRAINT PK_Branch
ALTER TABLE dbo.Branch ADD CONSTRAINT
PK_Branch PRIMARY KEY CLUSTERED 
(
cBraCode

) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]


--仓库资料
ALTER TABLE dbo.Warehouse DROP CONSTRAINT PK_Warehouse
ALTER TABLE dbo.Warehouse ADD CONSTRAINT
PK_Warehouse PRIMARY KEY CLUSTERED 
(
cWhCode
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]