hi,
i have a doubt, in sql server 2005 views. views created by using select statement.
can we write update and delete statements in views .
hi,
i have a doubt, in sql server 2005 views. views created by using select statement.
can we write update and delete statements in views .
Well you can delete from a view if that is what you are asking, but you can't have a view that deletes information. The view is a portion of data from the underlying tables. Provided that you have permissions, you can do the same data manipulation in views that you can do to a table directly.
So you can do something like:
DELETE FROM my_View WHERE id = 3;
from this MSDN article: Modifying Data Through a View,
The columns that are being modified in the view must reference the underlying data in the table columns directly. They cannot be derived in any other way, such as through:
The columns that are being modified cannot be affected by GROUP BY, HAVING, or DISTINCT clauses.
and see the article for remaining ...
In addition to the limited updating allowed on the view itself, you can use an INSTEAD OF
trigger to perform much more involved changes. INSTEAD OF
basically lets you intercept the update or delete, and perform almost any change. References: MSDN Article.