USE [aah]
GO
/****** Object: Index [PK_Cons_RecordCheckIn] Script Date: 01/03/2014 16:40:17 ******/
ALTER TABLE [dbo].[Cons_RecordCheckIn] ADD CONSTRAINT [PK_Cons_RecordCheckIn] PRIMARY KEY CLUSTERED
(
[NTime] ASC,
[UCardNo] 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
NTIME是datatime类型,我现在索引规则为NTime的左10位加UCardNo联合索引,应该怎样写?
------解决方案--------------------
可以试试用计算列:
alter table [dbo].[Cons_RecordCheckIn]
drop constraint[PK_Cons_RecordCheckIn]
go
--假设ntime是datetime类型
alter table [dbo].[Cons_RecordCheckIn]
add ntime_10 as convert(varchar(10),ntime,120) --如果是varchar的话:left(ntime,10)
go
ALTER TABLE [dbo].[Cons_RecordCheckIn]
ADD CONSTRAINT [PK_Cons_RecordCheckIn] PRIMARY KEY CLUSTERED
(
[ntime_10] ASC,
[UCardNo] 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