.NET and SQL Server interview questions -Show Practically Sql Server Views are updatable?
Shivprasad Koirala
Once you have completed the above step you will see that the respective View is added in the View folder.
Now let’s see that when we update the view the respective table is also updated or not.
Query:-
Update [Practice].[dbo].[Cust_View] set Customer_Contact = 96641122 where Customer_Name = 'Feroz'
Now just go to the table on which the view was created and check whether the table is updated or not, you will see that the table is also updated when you update the View.
Now let’s create a view based on two tables and try to update a view.
create view View_Cust as SELECT dbo.Customer.Customer_Name, dbo.Customer.Customer_Contact,dbo.[Order].Product_Name,dbo.[Order].Price FROM dbo.Customer INNER JOIN dbo.[Order] ON dbo.Customer.Order_ID = dbo.[Order].Order_ID
Update [Practice].[dbo].[View_Cust] set Customer_Contact = 098767554, Price = 4000 where Customer_Name = 'Feroz'
Error Message:- View or function 'Practice.dbo.View_Cust' is not updatable because the modification affects multiple base tables.
This means that when you try to update both the table’s column from the view then it is not allowed but you can update single table column.
Regards,