Modifying Data Through a View in SQL Server 2012
In this article, we will see how to modify the data of an underlying base table in SQL Server using a View.
In this article, we will see how to modify the data of an underlying base table in SQL Server using a View. A View is defined as a virtual table with data from various tables in the database. Views are most commonly used to provide security because it ensures that a user can only access the data they are intended to access and any remaining data is neither seen nor can be accessed by them. The remaining data is thereby automatically protected from unwanted users. So let's have a look at a practical example. The example is developed in SQL Server 2012 using the SQL Server Management Studio.
I have a table named EmployeeDetail.
Creating a View
CREATE VIEW View_Name (Column_Name1,Column2..)
Select_Statement [WITH CHECK OPTION ]
Now the following query defines the view.
Create view UpdateView
Modifying Data Through a View
SET emp_fname='Ram Kumar', emp_no=12
SELECT * FROM EmployeeDetail
Using the ALTER VIEW statement you can modify a view without dropping it. We can modify the view using the following query:
ALTER VIEW view_name
We can delete the view using the drop command as follows:
DROP VIEW view_name
DROPPING Multiple Views
You can drop a single view or multiple views at a time.
DROP VIEW view_name1, view_name2,..