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
Is the`SELECT` statement that defines the view. The statement can use more than one table and other views. Appropriate permissions are required to select from the objects referenced in the `SELECT` clause of the view that is created.
131
+
The`SELECT` statement that defines the view. The statement can use more than one table and other views. Appropriate permissions are required to select from the objects referenced in the `SELECT` clause of the view that is created.
132
132
133
-
A view does not have to be a simple subset of the rows and columns of one particular table. A view can be created that uses more than one table or other views with a `SELECT` clause of any complexity.
133
+
A view does not have to be a subset of the rows and columns of one particular table. A view can be created that uses more than one table or other views with a `SELECT` clause of any complexity.
134
134
135
135
In an indexed view definition, the `SELECT` statement must be a single table statement or a multitable `JOIN` with optional aggregation.
136
136
137
-
The `SELECT` clauses in a view definition cannot include the following:
137
+
The `SELECT` clauses in a view definition cannot include:
138
138
139
139
- An `ORDER BY` clause, unless there is also a `TOP` clause in the select list of the `SELECT` statement
If a view is not created with the `SCHEMABINDING` clause, run [sp_refreshview](../../relational-databases/system-stored-procedures/sp-refreshview-transact-sql.md) when changes are made to the objects underlying the view that affect the definition of the view. Otherwise, the view might produce unexpected results when it is queried.
190
190
191
-
When a view is created, information about the view is stored in the following catalog views: [sys.views](../../relational-databases/system-catalog-views/sys-views-transact-sql.md), [sys.columns](../../relational-databases/system-catalog-views/sys-columns-transact-sql.md), and [sys.sql_expression_dependencies](../../relational-databases/system-catalog-views/sys-sql-expression-dependencies-transact-sql.md). The text of the CREATE VIEW statement is stored in the [sys.sql_modules](../../relational-databases/system-catalog-views/sys-sql-modules-transact-sql.md) catalog view.
191
+
When a view is created, information about the view is stored in the following catalog views: [sys.views](../../relational-databases/system-catalog-views/sys-views-transact-sql.md), [sys.columns](../../relational-databases/system-catalog-views/sys-columns-transact-sql.md), and [sys.sql_expression_dependencies](../../relational-databases/system-catalog-views/sys-sql-expression-dependencies-transact-sql.md). The text of the `CREATE VIEW` statement is stored in the [sys.sql_modules](../../relational-databases/system-catalog-views/sys-sql-modules-transact-sql.md) catalog view.
192
192
193
-
A query that uses an index on a view defined with **numeric** or **float** expressions might have a result that is different from a similar query that does not use the index on the view. This difference can be caused by rounding errors during INSERT, DELETE, or UPDATE actions on underlying tables.
193
+
A query that uses an index on a view defined with **numeric** or **float** expressions might have a result that is different from a similar query that does not use the index on the view. This difference can be caused by rounding errors during `INSERT`, `DELETE`, or `UPDATE` actions on underlying tables.
194
194
195
-
The [!INCLUDE[ssDE](../../includes/ssde-md.md)] saves the settings of SET QUOTED_IDENTIFIER and SET ANSI_NULLS when a view is created. These original settings are used to parse the view when the view is used. Therefore, any client-session settings for SET QUOTED_IDENTIFIER and SET ANSI_NULLS do not affect the view definition when the view is accessed.
195
+
The [!INCLUDE[ssDE](../../includes/ssde-md.md)] saves the settings of `SET QUOTED_IDENTIFIER` and `SET ANSI_NULLS` when a view is created. These original settings are used to parse the view when the view is used. Therefore, any client-session settings for `SET QUOTED_IDENTIFIER` and `SET ANSI_NULLS` do not affect the view definition when the view is accessed.
196
196
197
197
In Azure Synapse Analytics, views do not support schema binding. Therefore, if changes are made to the underlying objects, you should drop and recreate the view to refresh the underlying metadata. For more information, see [T-SQL views with dedicated SQL pool and serverless SQL pool in Azure Synapse Analytics](/azure/synapse-analytics/sql/develop-views#limitations).
You can modify the data of an underlying base table through a view, as long as the following conditions are true:
208
208
209
-
- Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
209
+
- Any modifications, including `UPDATE`, `INSERT`, and `DELETE` statements, must reference columns from only one base table.
210
210
211
211
- The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following:
212
212
213
-
- An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP.
213
+
- An aggregate function: `AVG`, `COUNT`, `SUM`, `MIN`, `MAX`, `GROUPING`, `STDEV`, `STDEVP`, `VAR`, and `VARP`.
214
214
215
215
- A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable.
216
216
217
-
- The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses.
217
+
- The columns being modified are not affected by `GROUP BY`, `HAVING`, or `DISTINCT` clauses.
218
218
219
-
- TOP is not used anywhere in the *select_statement* of the view together with the WITH CHECK OPTION clause.
219
+
- TOP is not used anywhere in the *select_statement* of the view together with the `WITH CHECK OPTION` clause.
220
220
221
221
The previous restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. Generally, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] must be able to unambiguously trace modifications from the view definition to one base table. For more information, see [Modify Data Through a View](../../relational-databases/views/modify-data-through-a-view.md).
222
222
223
223
If the previous restrictions prevent you from modifying data directly through a view, consider the following options:
224
224
225
225
-**INSTEAD OF triggers**
226
226
227
-
INSTEAD OF triggers can be created on a view to make a view updatable. The INSTEAD OF trigger is executed instead of the data modification statement on which the trigger is defined. This trigger lets the user specify the set of actions that must happen to process the data modification statement. Therefore, if an INSTEAD OF trigger exists for a view on a specific data modification statement (INSERT, UPDATE, or DELETE), the corresponding view is updatable through that statement. For more information about INSTEAD OF triggers, see [DML Triggers](../../relational-databases/triggers/dml-triggers.md).
227
+
`INSTEAD OF` triggers can be created on a view to make a view updatable. The `INSTEAD OF` trigger is executed instead of the data modification statement on which the trigger is defined. This trigger lets the user specify the set of actions that must happen to process the data modification statement. Therefore, if an `INSTEAD OF` trigger exists for a view on a specific data modification statement (`INSERT`, `UPDATE`, or `DELETE`), the corresponding view is updatable through that statement. For more information about `INSTEAD OF` triggers, see [DML Triggers](../../relational-databases/triggers/dml-triggers.md).
228
228
229
229
-**Partitioned views**
230
230
231
-
If the view is a partitioned view, the view is updatable, subject to certain restrictions. When it is needed, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] distinguishes local partitioned views as the views in which all participating tables and the view are on the same instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], and distributed partitioned views as the views in which at least one of the tables in the view resides on a different or remote server.
231
+
If the view is a partitioned view, the view is updatable, subject to certain restrictions. When it is needed, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] distinguishes local partitioned views as the views in which all participating tables and the view are on the same instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], and distributed partitioned views as the views in which at least one of the tables in the view resides on a different or remote server.
232
232
233
233
## Partitioned views
234
234
@@ -237,7 +237,7 @@ You can modify the data of an underlying base table through a view, as long as t
237
237
> [!NOTE]
238
238
> The preferred method for partitioning data local to one server is through partitioned tables. For more information, see [Partitioned Tables and Indexes](../../relational-databases/partitions/partitioned-tables-and-indexes.md).
239
239
240
-
In designing a partitioning scheme, it must be clear what data belongs to each partition. For example, the data for the `Customers` table is distributed in three member tables in three server locations: `Customers_33` on `Server1`, `Customers_66` on `Server2`, and `Customers_99` on `Server3`.
240
+
When you design a partitioning scheme, it must be clear what data belongs to each partition. For example, the data for the `Customers` table is distributed in three member tables in three server locations: `Customers_33` on `Server1`, `Customers_66` on `Server2`, and `Customers_99` on `Server3`.
241
241
242
242
A partitioned view on `Server1` is defined in the following way:
243
243
@@ -321,7 +321,7 @@ FROM Tn;
321
321
322
322
If one or more of the member tables are remote, the view is called distributed partitioned view, and additional conditions apply. They are described later in this section.
323
323
324
-
- The same table cannot appear two times in the set of tables that are being combined with the UNION ALL statement.
324
+
- The same table cannot appear two times in the set of tables that are being combined with the `UNION ALL` statement.
325
325
326
326
- The member tables cannot have indexes created on computed columns in the table.
327
327
@@ -335,9 +335,9 @@ FROM Tn;
335
335
336
336
- The `INSERT` statement supplies values for all the columns in the view, even if the underlying member tables have a `DEFAULT` constraint for those columns or if they allow for `NULL` values. For those member table columns that have `DEFAULT` definitions, the statements cannot explicitly use the keyword `DEFAULT`.
337
337
338
-
- The value being inserted into the partitioning column satisfies at least one of the underlying constraints; otherwise, the insert action will fail with a constraint violation.
338
+
- The value being inserted into the partitioning column satisfies at least one of the underlying constraints; otherwise, the insert action fails with a constraint violation.
339
339
340
-
- `UPDATE` statements cannot specify the `DEFAULT` keyword as a value in the SET clause, even if the column has a `DEFAULT` value defined in the corresponding member table.
340
+
- `UPDATE` statements cannot specify the `DEFAULT` keyword as a value in the `SET` clause, even if the column has a `DEFAULT` value defined in the corresponding member table.
341
341
342
342
- Columns in the view that are an identity column in one or more of the member tables cannot be modified by using an `INSERT` or `UPDATE` statement.
343
343
@@ -356,7 +356,7 @@ FROM Tn;
356
356
357
357
For distributed partitioned views (when one or more member tables are remote), the following additional conditions apply:
358
358
359
-
- A distributed transaction will be started to guarantee atomicity across all nodes affected by the update.
359
+
- A distributed transaction is started to guarantee atomicity across all nodes affected by the update.
360
360
361
361
- Set the `XACT_ABORT` `SET`option to `ON` for `INSERT`, `UPDATE`, or `DELETE` statements to work.
362
362
@@ -390,15 +390,15 @@ The following examples use the [!INCLUDE [sssampledbobject-md](../../includes/ss
390
390
391
391
<a id="a-using-a-simple-create-view"></a>
392
392
393
-
### A. Use a simple CREATE VIEW
393
+
### A. Use CREATE VIEW to create a view
394
394
395
-
The following example creates a view by using a simple `SELECT` statement. A simple view is helpful when a combination of columns is queried frequently. The data from this view comes from the `HumanResources.Employee` and `Person.Person` tables of the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database. The data provides name and hire date information for the employees of [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)]. The view could be created for the person in charge of tracking work anniversaries but without giving this person access to all the data in these tables.
395
+
The following example creates a view by using a `SELECT` statement. A simple view is helpful when a combination of columns is queried frequently. The data from this view comes from the `HumanResources.Employee` and `Person.Person` tables of the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database. The data provides name and hire date information for the employees of [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)]. The view could be created for the person in charge of tracking work anniversaries but without giving this person access to all the data in these tables.
JOIN Person.Person AS p ON e.BusinessEntityID = p.BusinessEntityID ;
403
403
GO
404
404
```
@@ -427,7 +427,7 @@ GO
427
427
428
428
### C. Use WITH CHECK OPTION
429
429
430
-
The following example shows a view named `SeattleOnly` that references five tables and allows for data modifications to apply only to employees who live in Seattle.
430
+
The following example shows a view named `dbo.SeattleOnly` that references five tables and allows for data modifications to apply only to employees who live in Seattle.
431
431
432
432
```sql
433
433
CREATEVIEWdbo.SeattleOnly
@@ -467,7 +467,7 @@ GO
467
467
468
468
### E. Use partitioned data
469
469
470
-
The following example uses tables named `SUPPLY1`, `SUPPLY2`, `SUPPLY3`, and `SUPPLY4`. These tables correspond to the supplier tables from four offices, located in different countries/regions.
470
+
The following example uses tables named `SUPPLY1`, `SUPPLY2`, `SUPPLY3`, and `SUPPLY4`. These tables correspond to the supplier tables from four offices, located in different regions.
0 commit comments