标签:des style blog http io color ar os 使用
USE Northwind // 使用Northwind这个数据库
GO
CREATE VIEW vwSample
As
SELECT CustomerID, CompanyName, ContactName FROM CUSTOMERS
GO
use a view
SELECT * from vwSample
drop a view
DROP VIEW vwSample
3.Creating Views with the SCHEMABIND Option
使用了这个选项之后,view里面引用到的表的shema就不能被改变了。
Creating a view with the SCHEMABINDING option locks the tables being referred by the view and prevents any changes that may change the table schema.
Notice two important points while creating a view with SCHEMABINDING OPTION:
Here’s an example for a view with the SCHEMABIND OPTION:
CREATE VIEW vwSample
With SCHEMABINDING
As
SELECT
CustomerID,
CompanyName,
ContactName
FROM DBO.CUSTOMERS -- Two part name [ownername.objectname]
GO
4.Creating Views with the ENCRYPTION Option (一般情况下不要使用这个选项)
This option encrypts the definition of the view. Users will not be able to see the definition of the View after it is created.
USE NORTHWIND
GO
CREATE VIEW vwSample
With ENCRYPTION
As
SELECT
CustomerID,
CompanyName,
ContactName
FROM DBO.CUSTOMERS
GO
SELECT *
FROM SYSCOMMENTS
WHERE ID FROM SYSOBJECTS WHERE XTYPE = ‘V’ ANDThe view definition will be stored in an encrypted format in the system table named ‘syscomments’.
5.Indexed Views
给一个view创建index
SQL SERVER 2000 allows an index to be created on a View. Wow! Previous versions of SQL SERVER will not allow you to do this. But one important point to be noted here is that the first index on the View should be a UNIQUE CLUSTERED INDEX only. SQL SERVER 2000 will not allow you to create any other INDEX unless you have an UNIQUE CLUSTERED INDEX defined on the view.
Let’s check out a sample example for an Indexed View:
CREATE VIEW vwSample
As
SELECT
CustomerID,
CompanyName,
ContactName
FROM DBO.CUSTOMERS
GO
CREATE UNIQUE CLUSTERED INDEX indClustered
ON NORTHWIND.DBO.VWSAMPLE (CUSTOMERID)
GO
The above statement will create a unique clustered index on the View.
6. Almost any SQL that can be issued natively can be coded into a view; there are exceptions, however. For example, the UNION operator can not be used in a view and you cannot create a trigger on a view. view里不能进行union操作 7. The text of any view can be retrieved from the SQL Server system catalog using the system procedure sp_helptext (unless the view was created specifying WITH ENCRYPTION). For example, this statement: 使用命令来查看view的定义(也可以用这个命令来查看stored procedure的定义) sp_helptext Sample_view Might return the following output: Text CREATE VIEW Sample_View AS SELECT title, au_fname, au_lname FROM titles, titleauthor, authors WHERE titles.title_id=titleauthor.title_id AND authors.author_id=titleauthor.author_id It is also possible to rename a view using the system procedure sp_rename.标签:des style blog http io color ar os 使用
原文地址:http://www.cnblogs.com/760044827qq/p/4078845.html