USE DB GO IF NOT EXISTS(SELECT Name FROM SysColumns WHERE id=Object_Id('[HIS_QUEUE]') AND Name = 'InsertDateTime') BEGIN ALTER TABLE HIS_QUEUE ADD InsertDateTime datetime DEFAULT (CONVERT([date],CONVERT([varchar](100),getdate(),(23)),(23))) END GO IF NOT EXISTS(SELECT Name FROM SysColumns WHERE id=Object_Id('[QUEUEDETAIL]') AND Name = 'InsertDateTime') BEGIN ALTER TABLE QUEUEDETAIL ADD InsertDateTime datetime DEFAULT (CONVERT([date],CONVERT([varchar](100),getdate(),(23)),(23))) END GO update QUEUEDETAIL set InsertDateTime=(CONVERT([datetime], QUEUEDETAIL.APPOINTDATE ,(20))) update HIS_QUEUE set InsertDateTime=(CONVERT([datetime], HIS_QUEUE.[InsertDate] ,(20))) GO /****** Object: Index [DF_HISQUEUE_InsertDateTime] Script Date: 2023-05-31 10:21:54 ******/ IF EXISTS (SELECT name FROM sys.indexes WHERE name = N'DF_HISQUEUE_InsertDateTime') DROP INDEX [DF_HISQUEUE_InsertDateTime] ON [dbo].[HIS_QUEUE] WITH ( ONLINE = OFF ) GO /****** Object: Index [DF_HISQUEUE_InsertDateTime] Script Date: 2023-05-31 10:21:54 ******/ CREATE CLUSTERED INDEX [DF_HISQUEUE_InsertDateTime] ON [dbo].[HIS_QUEUE] ( InsertDateTime desc, [APPOINTSDATE] DESC, [APPKIND] DESC, [HISEXAMNO] DESC, [HISID] DESC, [NAME] DESC, [QUEUENAME] DESC, [EXECUTEDEPT] DESC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [DF_QUEUEDETAIL_InsertDateTime] Script Date: 2023-05-31 10:34:41 ******/ IF EXISTS (SELECT name FROM sys.indexes WHERE name = N'DF_QUEUEDETAIL_InsertDateTime') DROP INDEX [DF_QUEUEDETAIL_InsertDateTime] ON [dbo].[QUEUEDETAIL] WITH ( ONLINE = OFF ) GO /****** Object: Index [DF_QUEUEDETAIL_InsertDateTime] Script Date: 2023-05-31 10:34:41 ******/ CREATE CLUSTERED INDEX [DF_QUEUEDETAIL_InsertDateTime] ON [dbo].[QUEUEDETAIL] ( InsertDateTime desc, [APPOINTDATE] DESC, [APPKIND] DESC, [HISEXAMNO] DESC, [QUEUENAME] DESC, DIRECTION DESC, --CheckItemRemark DESC, PARTOFCHECK DESC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO
注:主键列默认为聚簇索引,聚簇索引只能有一个,非聚簇索引可以有多个
一般建议在对表创建索引时,使用日期类型的列创建且创建为降序。
标签:QUEUEDETAIL,OFF,DF,InsertDateTime,Server,索引,SQl,GO,DESC From: https://www.cnblogs.com/YYkun/p/17445531.html