创立索引视图的sql语句模板:
--=============================================
--CreateIndexedViewtemplate
--=============================================
USE<database_name,sysname,AdventureWorks>
GO
SETANSI_NULLS,ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,QUOTED_IDENTIFIERON
SETNUMERIC_ROUNDABORTOFF
IFobject_id(N<schema_name,sysname,dbo>.<view_name,sysname,SalesByOrderDate>,V)ISNOTNULL
DROPVIEW<schema_name,sysname,dbo>.<view_name,sysname,SalesByOrderDate>
GO
GO
CREATEUNIQUECLUSTEREDINDEX<view_name,sysname,SalesByOrderDate>_IndexedView
ON<schema_name,sysname,dbo>.<view_name,sysname,SalesByOrderDate>(<index_key_columns,,OrderDate>)
创立一般视图的sql语句模板:
--=============================================
--CreateViewtemplate
--=============================================
USE<database_name,sysname,AdventureWorks>
GO
IFobject_id(N<schema_name,sysname,dbo>.<view_name,sysname,Top10Sales>,V)ISNOTNULL
DROPVIEW<schema_name,sysname,dbo>.<view_name,sysname,Top10Sales>
GO