| title | Modify Data Through a View | |||
|---|---|---|---|---|
| description | Learn how to modify data through a view. | |||
| author | WilliamDAssafMSFT | |||
| ms.author | wiassaf | |||
| ms.reviewer | randolphwest | |||
| ms.date | 09/26/2025 | |||
| ms.service | sql | |||
| ms.subservice | table-view-index | |||
| ms.topic | how-to | |||
| ms.custom |
|
|||
| helpviewer_keywords |
|
|||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricsqldb]
You can modify the data of an underlying base table in SQL Server by using [!INCLUDE ssManStudioFull] or [!INCLUDE tsql].
See the section 'Updatable Views' in CREATE VIEW.
Requires UPDATE, INSERT, or DELETE permissions on the target table, depending on the action being performed.
-
In Object Explorer, expand the database that contains the view and then expand Views.
-
Right-click the view and select Edit Top 200 Rows.
-
You might need to modify the
SELECTstatement in the SQL pane to return the rows to be modified. -
In the Results pane, locate the row to be changed or deleted. To delete the row, right-click the row and select Delete. To change data in one or more columns, modify the data in the column.
You can't delete a row if the view references more than one base table. You can only update columns that belong to a single base table.
-
To insert a row, scroll down to the end of the rows and insert the new values.
You can't insert a row if the view references more than one base table.
-
In Object Explorer, connect to an instance of [!INCLUDE ssDE].
-
On the Standard bar, select New Query.
-
Copy and paste the following example into the query window and select Execute. This example changes the value in the
StartDateandEndDatecolumns for a specific employee by referencing columns in the viewHumanResources.vEmployeeDepartmentHistory. This view returns values from two tables. This statement succeeds because the columns being modified are from only one of the base tables.USE AdventureWorks2022; GO UPDATE HumanResources.vEmployeeDepartmentHistory SET StartDate = '20110203', EndDate = GETDATE() WHERE LastName = N'Smith' AND FirstName = 'Samantha'; GO
For more information, see UPDATE.
-
In Object Explorer, connect to an instance of [!INCLUDE ssDE].
-
On the Standard bar, select New Query.
-
Copy and paste the following example into the query window and select Execute. The example inserts a new row into the base table
HumanResources.Departmentby specifying the relevant columns from the viewHumanResources.vEmployeeDepartmentHistory. The statement succeeds because only columns from a single base table are specified and the other columns in the base table have default values.USE AdventureWorks2022; GO INSERT INTO HumanResources.vEmployeeDepartmentHistory (Department, GroupName) VALUES ('MyDepartment', 'MyGroup'); GO
For more information, see INSERT.