How do I determine which table in the multiuser view is being updated?

Update. My problem doesn't seem to be related to the SQL server. I have executed an update statement inside the database manually against the view and I was able to update the Bar table. I will close this and research the OleDbDataAdapters more as I think the problem is with them.

This question applies to MS SQL Server 2000. How to determine which table of the modified view can be changed?

I have the following view:

CREATE VIEW dbo.MyView
AS
SELECT     dbo.Foo.Id, dbo.Bar.Id, dbo.Foo.column1, dbo.Foo.column2,
           dbo.Foo.column3, dbo.Bar.column1, dbo.Bar.column2, 
           dbo.Bar.column3
FROM       dbo.Bar INNER JOIN
                  dbo.Foo ON dbo.Bar.Id = dbo.Foo.ForeignId

      

When I update this view (using VB.NET OleDbDataAdapters), I can update the Foo columns, but not the Bar columns. My investigation of this tells me that in such a multi-user view that MS SQL server allows you to update one of the tables. So my question is, how does SQL Server determine which table can be updated?

I tried a test where I edit the fields of a specific row from a view. Subsequently, I used the OleDbDataAdapter to update the view. Only changes to table Foo were accepted. Bar table edits were ignored (no exception was thrown).

Is there a way to predict which of the tables can be updated, or a way to control which one? What if I wanted Bar to be an updatable table instead of Foo?

Update: I found this on Google, MS SQL Server 2000 Unleased:

http://books.google.com/books?id=G2YqBS9CQ0AC&pg=RA1-PA713&lpg=RA1-PA713&dq=ms+sql+server+ "multitable + view" ++ updated & source = bl & ots = ZuQXIlEPbO & sig = JbgdDk5hU73a SLDdtMYZDs & hl = en & e = B-0SSq-aHZOitgPB38zgDQ & ca = X & OI = book_result & CT = result & resnum = 1 # PRA1-PA713, M1

(For some reason, the URL I'm trying to paste doesn't work with this site, sorry you need to copy and paste.)

What says:

  • Updating through a multi-user view cannot affect the main base table alone .
  • Unable to delete from multiple views.

But I still don't see the answer to my question.

Again, my question is:

How do you determine which table of the mutable view can be changed?

I understand that I can write two update statements, one for each table. I am concerned about something else. I need to audit code that uses views like the ones above and updates them. I was hoping to find a way to determine which parts of the updates would be ignored.

Example:

I am editing Bar.Column1 and then calling Update () method on OleDbDataAdapter. This results in the Bar table not being modified and no exception being thrown. If I edit Foo.Column2 then call Update (), the Foo table changes.

+1


a source to share


2 answers


You can update any table in the view, but only fields that are in the same table in this expression. If you need to update fields from two tables in a view, you must write two update statements.

Personally, I prefer not to update or delete from views at all. For this, I am using base tables.



There are also rules for updating a species. See Books on the Internet. Search: views-SQL Server, change data

+1


a source


You should be able to uniquely identify a row in a table by returning the primary key. Try to revert dbo.Bar.Id

to view and you should be able to edit the columns in the table Bar

.



-1


a source







All Articles