Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updatable views - SQL Server 2008

A question about updatable db views: I'm reading through some MSDN documentation on the subject, and I come across the following restriction:

Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.

I just want to be sure I understand the restriction. I'd like to use views in a couple of my media review projects. The relational data is spread throughout tables, but a view seems to be the best way to be able to consolidate the data I need from multiple tables (some of which are linked via foreign keys) into a centralized location. Since the columns would come from a variety of tables, does this mean I can't run one blanket INSERT or UPDATE to persist changes in all the columns?

like image 310
Major Productions Avatar asked Oct 05 '10 17:10

Major Productions


2 Answers

You can use an INSTEAD OF trigger on a view to keep your application only dealing with the view instead of the collection of base tables the view references.

Here is an example : Designing INSTEAD OF Triggers

like image 70
Dennis Allen Avatar answered Oct 23 '22 12:10

Dennis Allen


Yes that's what it means. I see no advantage to updating through a view since you have to know what the base tables involved are anyway.

like image 31
HLGEM Avatar answered Oct 23 '22 13:10

HLGEM