[Arrangement] conditions for SQL Server to create an index on the View

Source: Internet
Author: User

Creating an index on a view requires three conditions:
1. The view must be bound to the architecture.
To do this, you must add with schemabinding to the create view statement. If you are using the Enterprise Manager, right-click the blank area in the design field and select "bind to architecture" for properties ".
2. The index must be a unique index.
To do this, you must specify unique in create index.
3. The index must be a clustered index.
To do this, you must specify clustered in create index.
Example:
Create view viewfooWith schemabinding
As
Select ID...

Create unique clustered IndexIndex_viewfoo on viewfoo (ID)

 

**************************************** ***********************

View requirements
Before creating a clustered index on a view, the view must meet the following requirements:

When executing the create view statement, the options ansi_nulls and quoted_identifier must be set to on. The objectproperty function reports this information for the view through the execisansinullson or execisquotedidenton attribute.

To execute all the create table statements to create a table referenced by the view, the ansi_nulls option must be set to on.

A view cannot reference any other view. It can only reference a base table.

All base tables referenced by a view must be in the same database as the view, and the owner must be the same as the view.

You must use the schemabinding option to create a view. Schemabinding binds the view to the schema of the base table.

You must have used the schemabinding option to create user-defined functions referenced in the view.

Table and user-defined functions must be referenced by two names. The names of part 1, part 3, and Part 4 are not allowed.

All functions referenced by expressions in the view must be deterministic. The isdeterministic attribute of the objectproperty function reports whether the user-defined function is deterministic. For more information, see deterministic and non-deterministic functions.

The SELECT statement in the view cannot contain the following Transact-SQL syntax elements:
The * or table_name. * syntax cannot be used to specify columns in the selection list. The column name must be explicitly given.

You cannot specify a column name for a table that is used as a simple expression in multiple view columns. If all (or only one exception) references to a column are part of a complex expression or a function parameter, the column can be referenced multiple times. For example, the following selection list is invalid:
Select Columna, columnb, Columna

The user who executes the create index statement must be the view owner.
When executing the create index statement, the following set options must be set to on:
Ansi_nulls
Ansi_padding
Ansi_warnings
Arithabort
Concat_null_yields_null
Quoted_identifiers
The numeric_roundabort option must be set to off.
A view cannot contain text, ntext, or image columns, even if they are not referenced in the create index statement.
If the SELECT statement in the view definition specifies a group by clause, the key of the unique clustered index can only reference the column specified in the group by clause.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.