Friday 3 March 2017

What is View and how it is working:

View is similar like a mirror of an object. View is a virtual table where the physical data can be reflect from the real table. Most of the people are talking about Update , Insert and Delete operation in Views. Can we perform Update or Insert or Delete operation in views?
As per my knowledge we can't perform on it. How and why please check the below scenario. Views it does mean we are selecting data from a table into a virtual table. So we can't perform Update,Insert or Delete operation by the time of creation.
create view Select_exmaple
as
select FirstName,LastName from Employee
The above snippets showing FirstName, LastName from  Employee.
Now i am trying to create a new View with Update statement.
create view Update_T
as
update Employee set LastName='BBB' where LastName='CCC'
Following error will raise :
Msg 156, Level 15, State 1, Procedure Update_T, Line 35
Incorrect syntax near the keyword 'update'.
It meaning we can not perform Update statement by the time of creating Views. Similarly if try to insert some values into views we will get same error.
Once you create the View with select statement then you can use Update,Insert and Delete Query for that particular View.
update Select_exmaple set LastName='CCC' where LastName='BBB'
The above statement will effect to the physical table  as per updated in views.



No comments:

Post a Comment