Table Creation Index
Create index index name on table name (field name ASC);
View Creation Index
Creating a view index first to bind the view to the schema
Alter view view_prod_productprogress with SCHEMABINDING
as
SELECT * FROM dbo. T1 as a INNER JOIN dbo. T2 as B on a.id=b.id
When binding to schemas, the use of a table consists of two parts, the dbo. T1
Next Create the Index
if (exists (SELECT * from sys.indexes where name = ' Idx_prod_productprogress_sht '))
DROP Index View_prod_productprogr Ess.idx_prod_productprogress_sht
Go
CREATE index Idx_prod_productprogress_sht
on
view_prod_ Productprogress (Productprogresssht);
Error: Unable to create index on view ' view_prod_productprogress '. It does not have a unique clustered index.
So the first thing to do is create a clustered index
if (exists (SELECT * from sys.indexes where name = ' Idx_prod_productprogress_sht '))
DROP Index View_prod_productprogr Ess.idx_prod_productprogress_sht
Go
create UNIQUE CLUSTERED index Idx_prod_productprogress_sht on
View_prod_productprogress (Productprogresssht);
Note
A standard view that is converted to an indexed view must adhere to the following rules: A. The view must use the with schemabinding option to create; if there is no with schemabinding when creating the view, an error will be made when attempting to create the view: ... Because the view is not bound to schema B. You cannot use other views, export tables, rowset functions, or self-queries in this view, which means you can use only table; C. The base table used by the view must and the view belong to the same owner; D. Views can only be linked to tables in the same database; E. Views cannot contain an external link or a self-link, that is, you can only use inner join when linking tables and cannot make the same table before or after inner join, and you cannot use left JOIN or LEFT (right) OUTER JOIN ; F. A view cannot contain a UNION clause, a TOP clause, a order by clause, a HAVING clause, a rollup clause, a cube clause, a Compute clause, a compute by clause, or a distinct keyword; G. Views do not allow certain aggregate functions, such as: Count (*) can use COUNT_BIG (*) instead, AVG (), Max (), Min (), Stdev (), STDEVP (), Var (), or VarP (); H. Views cannot use statements such as select * , which means that all fields of the view must display the specified; I. Views cannot contain text, ntext, and image types of columns; J. If the view contains a group by clause, then he must include COUNT_BIG (*); K in the Select column. All the standard and user-defined functions in the view must be referenced by using the two-segment name, which is the owner. The name of the table or function; L. All basic tables and views must be created with the Set Ansi_Nulls On ; M. When an IUD is executed when an index is created or after an index is created, the: must be displayed or implicitly executed
set ansi_nulls on Set ANSI_PADDING ON set ansi_warnings on Set arithabort on S et concat_null_yields_null on Set quoted_ identifier on set numeric_roundabort off N. Indexed views can only be created in the enterprise or development version of sql server2000 or later.
After an indexed view is created on a table, DELETE operation is performed on it The Times error:delete failed,
Because the settings for the following set options are incorrect: ' Concat_null_yields_null, Ansi_padding,arithabort ', removing this view will solve the problem.