sql-server-2008 - 从 View 及其所有相关表中删除记录

标签 sql-server-2008 view delete-row

我正在使用 SQL Server Management Studio 2008。

我想从一个 View 中删除一条记录,该 View 在所有列的记录中显示空值。

我不知道,我从哪个表中得到这条空记录。

我检查了所有为 View 连接的表,但没有一个表包含空记录。

谁能帮我从我的 View 和所有相关表中删除这条空记录..?

因为我在许多其他页面中使用此 View ,它会在每个页面中产生空值错误。

当我尝试从 View 中删除这条记录时,它显示如下错误

"Msg 4405, Level 16, State 1, Line 1
View or function 'viewGetProgressOverview' is not updatable because the modification affects multiple base tables."

最佳答案

If you have created a View in SQL which is based on a single table – the DML operations you perform on the view are automatically propagated to the base table.

However, when you have joined multiple tables to create a view you will run into below error if you execute a DML statement against the view:

Msg 4405, Level 16, State 1, Line 1
View or function 'ViewName' is not updatable because the modification affects
multiple base tables.

Update join views规则如下:

Any INSERT, UPDATE, or DELETE operation on a join view can modify only one underlying base table at a time.

UPDATE Rule

All updatable columns of a join view must map to columns of a key-preserved table. See "Key-Preserved Tables" for a discussion of key-preserved tables. If the view is defined with the WITH CHECK OPTION clause, then all join columns and all columns of repeated tables are non-updatable.

DELETE Rule

Rows from a join view can be deleted as long as there is exactly one key-preserved table in the join. If the view is defined with the WITH CHECK OPTION clause and the key preserved table is repeated, then the rows cannot be deleted from the view.

INSERT Rule

An INSERT statement must not explicitly or implicitly refer to the columns of a nonkey preserved table. If the join view is defined with the WITH CHECK OPTION clause, INSERT statements are not permitted.

引用:-

Inserting to a View – INSTEAD OF TRIGGER – SQL Server

Sql updatable view with joined tables

关于sql-server-2008 - 从 View 及其所有相关表中删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030457/

相关文章:

c# - Dapper 错误将 tinyint 解析为短?

php - mysql View 显示 1242 错误

sql - 加入具有相同列名的 2 个表时出现歧义列错误

sql-server - 为什么字符 '£' 在 SQL Server 中更新时将转换为 "L"

android - 为什么 "SurfaceView"比自定义的 "view"慢?

c++ - 命名类(可能是代理)的目的是允许对项目进行排序和删除,而无需修改基础容器

java - 如何使用deleteRow()方法从多个表中删除行

Python:当行元素由行名称中的字符串组成时删除行

mysql - 如何从我的 MySQL 表中删除相似的行?

sql - 无法通过 SSMS 访问 MSDB 文件夹中的 SSIS 包