Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>SQL Server views can be updated just as if they were a single table, as long as they conform to certain conditions.</p> <p>From the <a href="http://msdn.microsoft.com/en-us/library/ms187956.aspx" rel="nofollow">documentation</a>:</p> <blockquote> <p>Updatable Views</p> <p>You can modify the data of an underlying base table through a view, as long as the following conditions are true:</p> <p>Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.</p> <p>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:</p> <p>An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP.</p> <p>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.</p> <p>The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses.</p> <p>TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause.</p> <p>The previous restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. Generally, the Database Engine must be able to unambiguously trace modifications from the view definition to one base table. For more information, see Modify Data Through a View.</p> </blockquote> <p>I don't believe SSMS is doing anything special - editing the contents of a view offers exactly the same functionality as editing the contents of a table. If the user attempts to make a change that does not conform to the above conditions, SSMS will likely display an error.</p> <blockquote> <p>How does SSMS infer which primary key to use, even if the key is not in the view?</p> </blockquote> <p>It doesn't. SQL Server does since only one underlying table can be edited at a time.</p> <blockquote> <p>How does SSMS determine which column inside a view can or can not be edited / inserted / deleted etc.?</p> </blockquote> <p>Again, it's SQL Server that determines this, not SSMS.</p> <blockquote> <p>What would be my best option to replicate this inside a .NET application?</p> </blockquote> <p>As long as all your views conform to the above conditions, simply do the same as you're doing for tables, but be ready to handle the errors from users doing something they can't (this implies some user training will be required, just as it would be if they were using SSMS directly).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload