sql重建索引的方法


/****** Object:  Index [PK_CSM_POS_CARDPACKAGEDETAIL]    Script Date: 06/09/2013 14:07:00 ******/
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CSM_Pos_CardPackageDetail]') AND name = N'PK_CSM_POS_CARDPACKAGEDETAIL')
ALTER TABLE [dbo].[CSM_Pos_CardPackageDetail] DROP CONSTRAINT [PK_CSM_POS_CARDPACKAGEDETAIL]
GO

--这里可以做一些修改索引字段的动作(重命名,修改类型等),例如
EXECUTE sys.sp_rename @objname = N'[dbo].[CSM_Pos_CardPackageDetail].[UserID]', @newname = N'VipID', @objtype = 'COLUMN'
GO

/****** Object:  Index [PK_CSM_POS_CARDPACKAGEDETAIL]    Script Date: 06/09/2013 14:07:01 ******/
ALTER TABLE [dbo].[CSM_Pos_CardPackageDetail] ADD  CONSTRAINT [PK_CSM_POS_CARDPACKAGEDETAIL] PRIMARY KEY CLUSTERED 
(
	[CompanyID] ASC,
	[ShopID] ASC,
	[VipID] ASC,
	[ServicePackageID] ASC,
	[SourceBillNo] ASC,
	[SourceBillSequence] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

你可能感兴趣的:(sql)