You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/views/create-indexed-views.md
+42-42Lines changed: 42 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,73 +33,73 @@ ms.workload: "Active"
33
33
## <aname="BeforeYouBegin"></a> Before You Begin
34
34
The following steps are required to create an indexed view and are critical to the successful implementation of the indexed view:
35
35
36
-
1. Verify the SET options are correct for all existing tables that will be referenced in the view.
37
-
2. Verify that the SET options for the session are set correctly before you create any tables and the view.
38
-
3. Verify that the view definition is deterministic.
39
-
4. Create the view by using the `WITH SCHEMABINDING` option.
40
-
5. Create the unique clustered index on the view.
36
+
1. Verify the SET options are correct for all existing tables that will be referenced in the view.
37
+
2. Verify that the SET options for the session are set correctly before you create any tables and the view.
38
+
3. Verify that the view definition is deterministic.
39
+
4. Create the view by using the `WITH SCHEMABINDING` option.
40
+
5. Create the unique clustered index on the view.
41
41
42
42
> [!IMPORTANT]
43
-
> When executing DML<sup>1</sup> on a table referenced by a large number of indexed views, or fewer but very complex indexed views, those referenced indexed views will have to be updated as well. As a result, DML query performance can degrade significantly, or in some cases, a query plan cannot even be produced.
44
-
> In such scenarios, test your DML queries before production use, analyze the query plan and tune/simplify the DML statement.
45
-
>
46
-
> <sup>1</sup> Such as UPDATE, DELETE or INSERT operations.
43
+
> When executing DML<sup>1</sup> on a table referenced by a large number of indexed views, or fewer but very complex indexed views, those referenced indexed views will have to be updated as well. As a result, DML query performance can degrade significantly, or in some cases, a query plan cannot even be produced.
44
+
> In such scenarios, test your DML queries before production use, analyze the query plan and tune/simplify the DML statement.
45
+
>
46
+
> <sup>1</sup> Such as UPDATE, DELETE or INSERT operations.
47
47
48
48
### <aname="Restrictions"></a> Required SET Options for Indexed Views
49
-
Evaluating the same expression can produce different results in the [!INCLUDE[ssDE](../../includes/ssde-md.md)] when different SET options are active when the query is executed. For example, after the SET option `CONCAT_NULL_YIELDS_NULL` is set to ON, the expression **'**abc**'** + NULL returns the value NULL. However, after `CONCAT_NULL_YIEDS_NULL` is set to OFF, the same expression produces **'**abc**'**.
49
+
Evaluating the same expression can produce different results in the [!INCLUDE[ssDE](../../includes/ssde-md.md)] when different SET options are active when the query is executed. For example, after the SET option `CONCAT_NULL_YIELDS_NULL` is set to ON, the expression `'abc' + NULL` returns the value `NULL`. However, after `CONCAT_NULL_YIEDS_NULL` is set to OFF, the same expression produces `'abc'`.
50
50
51
-
To make sure that the views can be maintained correctly and return consistent results, indexed views require fixed values for several SET options. The SET options in the following table must be set to the values shown in the **Required Value** column whenever the following conditions occur:
51
+
To make sure that the views can be maintained correctly and return consistent results, indexed views require fixed values for several SET options. The SET options in the following table must be set to the values shown in the **Required Value** column whenever the following conditions occur:
52
52
53
-
- The view and subsequent indexes on the view are created.
53
+
- The view and subsequent indexes on the view are created.
54
54
55
-
- The base tables referenced in the view at the time the table is created.
55
+
- The base tables referenced in the view at the time the table is created.
56
56
57
-
- There is any insert, update, or delete operation performed on any table that participates in the indexed view. This requirement includes operations such as bulk copy, replication, and distributed queries.
57
+
- There is any insert, update, or delete operation performed on any table that participates in the indexed view. This requirement includes operations such as bulk copy, replication, and distributed queries.
58
58
59
-
- The indexed view is used by the query optimizer to produce the query plan.
59
+
- The indexed view is used by the query optimizer to produce the query plan.
60
60
61
-
|SET options|Required value|Default server value|Default<br /><br /> OLE DB and ODBC value|Default<br /><br /> DB-Library value|
<sup>1</sup> Setting `ANSI_WARNINGS` to ON implicitly sets `ARITHABORT` to ON.
71
+
<sup>1</sup> Setting `ANSI_WARNINGS` to ON implicitly sets `ARITHABORT` to ON.
72
72
73
-
If you are using an OLE DB or ODBC server connection, the only value that must be modified is the `ARITHABORT` setting. All DB-Library values must be set correctly either at the server level by using **sp_configure** or from the application by using the SET command.
73
+
If you are using an OLE DB or ODBC server connection, the only value that must be modified is the `ARITHABORT` setting. All DB-Library values must be set correctly either at the server level by using **sp_configure** or from the application by using the SET command.
74
74
75
75
> [!IMPORTANT]
76
76
> We strongly recommend that you set the `ARITHABORT` user option to ON server-wide as soon as the first indexed view or index on a computed column is created in any database on the server.
77
77
78
78
### Deterministic Views
79
-
The definition of an indexed view must be deterministic. A view is deterministic if all expressions in the select list, as well as the `WHERE` and `GROUP BY` clauses, are deterministic. Deterministic expressions always return the same result any time they are evaluated with a specific set of input values. Only deterministic functions can participate in deterministic expressions. For example, the `DATEADD` function is deterministic because it always returns the same result for any given set of argument values for its three parameters. `GETDATE` is not deterministic because it is always invoked with the same argument, but the value it returns changes each time it is executed.
79
+
The definition of an indexed view must be deterministic. A view is deterministic if all expressions in the select list, as well as the `WHERE` and `GROUP BY` clauses, are deterministic. Deterministic expressions always return the same result any time they are evaluated with a specific set of input values. Only deterministic functions can participate in deterministic expressions. For example, the `DATEADD` function is deterministic because it always returns the same result for any given set of argument values for its three parameters. `GETDATE` is not deterministic because it is always invoked with the same argument, but the value it returns changes each time it is executed.
80
80
81
-
To determine whether a view column is deterministic, use the **IsDeterministic** property of the [COLUMNPROPERTY](../../t-sql/functions/columnproperty-transact-sql.md) function. To determine if a deterministic column in a view with schema binding is precise, use the **IsPrecise** property of the COLUMNPROPERTY function. COLUMNPROPERTY returns 1 if TRUE, 0 if FALSE, and NULL for input that is not valid. This means the column is not deterministic or not precise.
81
+
To determine whether a view column is deterministic, use the **IsDeterministic** property of the [COLUMNPROPERTY](../../t-sql/functions/columnproperty-transact-sql.md) function. To determine if a deterministic column in a view with schema binding is precise, use the **IsPrecise** property of the `COLUMNPROPERTY` function. `COLUMNPROPERTY` returns 1 if TRUE, 0 if FALSE, and NULL for input that is not valid. This means the column is not deterministic or not precise.
82
82
83
-
Even if an expression is deterministic, if it contains float expressions, the exact result may depend on the processor architecture or version of microcode. To ensure data integrity, such expressions can participate only as non-key columns of indexed views. Deterministic expressions that do not contain float expressions are called precise. Only precise deterministic expressions can participate in key columns and in WHERE or GROUP BY clauses of indexed views.
83
+
Even if an expression is deterministic, if it contains float expressions, the exact result may depend on the processor architecture or version of microcode. To ensure data integrity, such expressions can participate only as non-key columns of indexed views. Deterministic expressions that do not contain float expressions are called precise. Only precise deterministic expressions can participate in key columns and in `WHERE` or `GROUP BY` clauses of indexed views.
84
84
85
85
### Additional Requirements
86
-
In addition to the SET options and deterministic function requirements, the following requirements must be met:
86
+
In addition to the SET options and deterministic function requirements, the following requirements must be met:
87
87
88
-
- The user that executes `CREATE INDEX` must be the owner of the view.
88
+
- The user that executes `CREATE INDEX` must be the owner of the view.
89
89
90
-
- When you create the index, the `IGNORE_DUP_KEY` option must be set to OFF (the default setting).
90
+
- When you create the index, the `IGNORE_DUP_KEY` option must be set to OFF (the default setting).
91
91
92
-
- Tables must be referenced by two-part names, *schema***.***tablename* in the view definition.
92
+
- Tables must be referenced by two-part names, *schema***.***tablename* in the view definition.
93
93
94
-
- User-defined functions referenced in the view must be created by using the `WITH SCHEMABINDING` option.
94
+
- User-defined functions referenced in the view must be created by using the `WITH SCHEMABINDING` option.
95
95
96
-
- Any user-defined functions referenced in the view must be referenced by two-part names, *schema***.***function*.
96
+
- Any user-defined functions referenced in the view must be referenced by two-part names, *\<schema>***.***\<function>*.
97
97
98
-
- The data access property of a user-defined function must be `NO SQL`, and external access property must be `NO`.
98
+
- The data access property of a user-defined function must be `NO SQL`, and external access property must be `NO`.
99
99
100
-
- Common language runtime (CLR) functions can appear in the select list of the view, but cannot be part of the definition of the clustered index key. CLR functions cannot appear in the WHERE clause of the view or the ON clause of a JOIN operation in the view.
100
+
- Common language runtime (CLR) functions can appear in the select list of the view, but cannot be part of the definition of the clustered index key. CLR functions cannot appear in the WHERE clause of the view or the ON clause of a JOIN operation in the view.
101
101
102
-
- CLR functions and methods of CLR user-defined types used in the view definition must have the properties set as shown in the following table.
102
+
- CLR functions and methods of CLR user-defined types used in the view definition must have the properties set as shown in the following table.
103
103
104
104
|Property|Note|
105
105
|--------------|----------|
@@ -134,12 +134,12 @@ ms.workload: "Active"
134
134
- If the view definition contains a `GROUP BY` clause, the key of the unique clustered index can reference only the columns specified in the `GROUP BY` clause.
135
135
136
136
> [!IMPORTANT]
137
-
> Indexed views are not supported on top of temporal queries (queries that use `FOR SYSTEM_TIME` clause)
137
+
> Indexed views are not supported on top of temporal queries (queries that use `FOR SYSTEM_TIME` clause).
138
138
139
139
### <aname="Recommendations"></a> Recommendations
140
140
When you refer to **datetime** and **smalldatetime** string literals in indexed views, we recommend that you explicitly convert the literal to the date type you want by using a deterministic date format style. For a list of the date format styles that are deterministic, see [CAST and CONVERT (Transact-SQL)](../../t-sql/functions/cast-and-convert-transact-sql.md). For more information about deterministic and nondeterministic expressions, see the [Considerations](#nondeterministic) section in this page.
141
141
142
-
When you execute DML (such as UPDATE, DELETE or INSERT) on a table referenced by a large number of indexed views, or fewer but very complex indexed views, those indexed views will have to be updated as well during DML execution. As a result, DML query performance may degrade significantly, or in some cases, a query plan cannot even be produced. In such scenarios, test your DML queries before production use, analyze the query plan and tune/simplify the DML statement.
142
+
When you execute DML (such as `UPDATE`, `DELETE` or `INSERT`) on a table referenced by a large number of indexed views, or fewer but very complex indexed views, those indexed views will have to be updated as well during DML execution. As a result, DML query performance may degrade significantly, or in some cases, a query plan cannot even be produced. In such scenarios, test your DML queries before production use, analyze the query plan and tune/simplify the DML statement.
143
143
144
144
### <aname="Considerations"></a> Considerations
145
145
The setting of the **large_value_types_out_of_row** option of columns in an indexed view is inherited from the setting of the corresponding column in the base table. This value is set by using [sp_tableoption](../../relational-databases/system-stored-procedures/sp-tableoption-transact-sql.md). The default setting for columns formed from expressions is 0. This means that large value types are stored in-row.
@@ -157,7 +157,7 @@ When you execute DML (such as UPDATE, DELETE or INSERT) on a table referenced by
157
157
### <aname="Security"></a> Security
158
158
159
159
#### <aname="Permissions"></a> Permissions
160
-
Requires CREATE VIEW permission in the database and ALTER permission on the schema in which the view is being created.
160
+
Requires **CREATE VIEW** permission in the database and **ALTER** permission on the schema in which the view is being created.
161
161
162
162
## <aname="TsqlProcedure"></a> Using Transact-SQL
163
163
@@ -216,7 +216,7 @@ When you execute DML (such as UPDATE, DELETE or INSERT) on a table referenced by
216
216
GO
217
217
```
218
218
219
-
For more information, see [CREATE VIEW (Transact-SQL)](../../t-sql/statements/create-view-transact-sql.md).
219
+
For more information, see [CREATE VIEW (Transact-SQL)](../../t-sql/statements/create-view-transact-sql.md).
220
220
221
221
## See Also
222
222
[CREATE INDEX (Transact-SQL)](../../t-sql/statements/create-index-transact-sql.md)
0 commit comments