use mlk;
GO
SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
--Create view with schemabinding.
IF OBJECT_ID ('dbo.mtlevel1', 'view') IS NOT NULL
DROP VIEW dbo.mtlevel1;
GO
CREATE VIEW dbo.mtlevel1
WITH SCHEMABINDING AS
SELECT
COUNT_BIG(*) AS TotalNumber,
Sum(dbo.TT_MT_LOG.MT_TOTAL) AS Demolition,
Sum(CASE WHEN dbo.TT_MT_LOG.MT_STATE=2 THEN 1 else 0 END) AS SendSuccess,
Sum(CASE WHEN dbo.TT_MT_LOG.MT_STATE=3 THEN 1 else 0 END) AS SendFailed,
Sum(CASE WHEN dbo.TT_MT_LOG.MT_STATE=4 THEN 1 else 0 END) AS ReceiveSuccess,
Sum(CASE WHEN dbo.TT_MT_LOG.MT_STATE=5 THEN 1 else 0 END) AS ReceiveFailed,
Sum(CASE WHEN dbo.TT_MT_LOG.MT_STATE=8 THEN 1 else 0 END) AS ReceiveNoState,
dbo.TT_MT_LOG.APP_PARAMETER1 AS BizCode,
CONVERT(datetime,CONVERT (CHAR (10),dbo.TT_MT_LOG.SEND_TIME,120)) AS Days
FROM
dbo.TT_MT_LOG where MT_TOTAL is not null
GROUP BY
dbo.TT_MT_LOG.APP_PARAMETER1,
CONVERT(datetime,CONVERT (CHAR (10),dbo.TT_MT_LOG.SEND_TIME,120))
GO
CREATE UNIQUE CLUSTERED INDEX mt_index ON mtlevel1(Days DESC,BizCode);
GO
创建视图索引报错了,不太懂这个,原因我不知道啊,大神帮我看看。
错误:
[SQL]
CREATE UNIQUE CLUSTERED INDEX mt_index ON mtlevel1(Days DESC,BizCode)
[Err] 42000 - [SQL Server]Column 'Days' in view 'mtlevel1' cannot be used in an index or statistics or as a partition key because it is non-deterministic.
改创建非聚集索引吧。
CONVERT(datetime,CONVERT (CHAR (10),dbo.TT_MT_LOG.SEND_TIME,120),120)