以下是利用sql语句对
视图与
索引视图进行新增,修改,删除的语句模板,来源于msdn。具体语法约定请参考下面链接:
Transact-SQL 语法约定 (Transact-SQL)创建索引视图的sql语句模板:
-- =============================================
-- Create Indexed View template
-- =============================================
USE <database_name, sysname, AdventureWorks >
GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
IF object_id(N'<schema_name, sysname, dbo >.<view_name, sysname, SalesByOrderDate >', 'V') IS NOT NULL
DROP VIEW <schema_name, sysname, dbo >.<view_name, sysname, SalesByOrderDate >
GO
CREATE VIEW <schema_name, sysname, dbo >.<view_name, sysname, SalesByOrderDate >
WITH SCHEMABINDING AS
<select_statement, , SELECT OrderDate, count_big(*) C, SUM(TotalDue) DateTotal FROM Sales.SalesOrderHeader GROUP BY OrderDate >
GO
CREATE UNIQUE CLUSTERED INDEX <view_name, sysname, SalesByOrderDate >_IndexedView
ON <schema_name, sysname, dbo >.<view_name, sysname, SalesByOrderDate >(<index_key_columns, , OrderDate >)
创建普通视图的sql语句模板:
-- =============================================
-- Create View template
-- =============================================
USE <database_name, sysname, AdventureWorks >
GO
IF object_id(N'<schema_name, sysname, dbo >.<view_name, sysname, Top10Sales >', 'V') IS NOT NULL
DROP VIEW <schema_name, sysname, dbo >.<view_name, sysname, Top10Sales >
GO
CREATE VIEW <schema_name, sysname, dbo >.<view_name, sysname, Top10Sales > AS
<select_statement, , SELECT TOP 10 * FROM Sales.SalesOrderHeader ORDER BY TotalDue DESC >
删除视图的sql语句模板:
-- =============================================
-- Drop View template
-- =============================================
DROP VIEW <schema_name, sysname, dbo >.<view_name, sysname, Top10Sales >
=