Skip to content

Commit 011ef78

Browse files
20250409 edit pass acrolinx
1 parent 0592de2 commit 011ef78

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

docs/t-sql/statements/create-view-transact-sql.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ CREATE [ OR ALTER ] VIEW [ schema_name . ] view_name [ ( column_name [ ,...n ]
128128

129129
*select_statement*
130130

131-
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.
132132

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.
134134

135135
In an indexed view definition, the `SELECT` statement must be a single table statement or a multitable `JOIN` with optional aggregation.
136136

137-
The `SELECT` clauses in a view definition cannot include the following:
137+
The `SELECT` clauses in a view definition cannot include:
138138

139139
- An `ORDER BY` clause, unless there is also a `TOP` clause in the select list of the `SELECT` statement
140140

@@ -188,11 +188,11 @@ CREATE [ OR ALTER ] VIEW [ schema_name . ] view_name [ ( column_name [ ,...n ]
188188

189189
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.
190190

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.
192192

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.
194194

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.
196196

197197
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).
198198

@@ -206,29 +206,29 @@ CREATE [ OR ALTER ] VIEW [ schema_name . ] view_name [ ( column_name [ ,...n ]
206206

207207
You can modify the data of an underlying base table through a view, as long as the following conditions are true:
208208

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.
210210

211211
- 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:
212212

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`.
214214

215215
- 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.
216216

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.
218218

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.
220220

221221
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).
222222

223223
If the previous restrictions prevent you from modifying data directly through a view, consider the following options:
224224

225225
- **INSTEAD OF triggers**
226226

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).
228228

229229
- **Partitioned views**
230230

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.
232232

233233
## Partitioned views
234234

@@ -237,7 +237,7 @@ You can modify the data of an underlying base table through a view, as long as t
237237
> [!NOTE]
238238
> 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).
239239
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`.
241241

242242
A partitioned view on `Server1` is defined in the following way:
243243

@@ -321,7 +321,7 @@ FROM Tn;
321321
322322
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.
323323
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.
325325
326326
- The member tables cannot have indexes created on computed columns in the table.
327327
@@ -335,9 +335,9 @@ FROM Tn;
335335
336336
- 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`.
337337
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.
339339
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.
341341
342342
- 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.
343343
@@ -356,7 +356,7 @@ FROM Tn;
356356
357357
For distributed partitioned views (when one or more member tables are remote), the following additional conditions apply:
358358
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.
360360
361361
- Set the `XACT_ABORT` `SET`option to `ON` for `INSERT`, `UPDATE`, or `DELETE` statements to work.
362362
@@ -390,15 +390,15 @@ The following examples use the [!INCLUDE [sssampledbobject-md](../../includes/ss
390390
391391
<a id="a-using-a-simple-create-view"></a>
392392
393-
### A. Use a simple CREATE VIEW
393+
### A. Use CREATE VIEW to create a view
394394
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.
396396
397397
```sql
398398
CREATE VIEW hiredate_view
399-
AS
399+
AS
400400
SELECT p.FirstName, p.LastName, e.BusinessEntityID, e.HireDate
401-
FROM HumanResources.Employee e
401+
FROM HumanResources.Employee AS e
402402
JOIN Person.Person AS p ON e.BusinessEntityID = p.BusinessEntityID ;
403403
GO
404404
```
@@ -427,7 +427,7 @@ GO
427427

428428
### C. Use WITH CHECK OPTION
429429

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.
431431

432432
```sql
433433
CREATE VIEW dbo.SeattleOnly
@@ -467,7 +467,7 @@ GO
467467

468468
### E. Use partitioned data
469469

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.
471471

472472
```sql
473473
--Create the tables and insert the values.
@@ -515,17 +515,9 @@ GO
515515

516516
<a id="f-creating-a-simple-view"></a>
517517

518-
### F. Create a simple view
518+
<a id="#g-create-a-view-by-joining-two-tables"></a>
519519

520-
The following example creates a view by selecting only some of the columns from the source table.
521-
522-
```sql
523-
CREATE VIEW DimEmployeeBirthDates AS
524-
SELECT FirstName, LastName, BirthDate
525-
FROM DimEmployee;
526-
```
527-
528-
### G. Create a view by joining two tables
520+
### F. Create a view by joining two tables
529521

530522
The following example creates a view by using a `SELECT` statement with an `OUTER JOIN`. The results of the join query populate the view.
531523

0 commit comments

Comments
 (0)