Online Training for MVC Web Designing Development, MS SQL, Digital Marketing

SQL View, Create View, Alter View, SQL Tutorial

In earlier article you have learned SQL Table, now you learn SQL View

What is View in SQL DATABASE?

A VIEW is a logical set of data, can be from one table or multiple tables. Views do not contain data of their own.

View is designed for restricting direct access to the database, and exposing data as per user role.

You can say View is a just a Select statement saved in database in form of an object for better re-usability.

Why do we need View?
View is very useful when you don’t want to give access of all data of any table to particular user group, or you want to give access to some set of data without giving access of all tables.

How to ceate view in SQL Database

We can create view from one table or joining multiple tables, here is an example
Create view [vwEmpSocialNetwork]
SELECT tbEmpSocialNetwork.EmpSocialId, tbEmpSocialNetwork.Facebook, tbEmpSocialNetwork.LinkedIn, tbEmpSocialNetwork.Twitter,
tbEmpSocialNetwork.PersonalBlog, tbEmpSocialNetwork.Updated, tbEmployee.FirstName, tbEmployee.MiddleName,
tbEmployee.LastName, tbEmployee.EmployeeId
FROM tbEmployee left outer JOIN tbEmpSocialNetwork
ON tbEmployee.EmployeeId = tbEmpSocialNetwork.EmployeeId

How to alter view SQL Database

Alter view viewName
Alter view [vwEmpSocialNetwork]
// Specify all column names you want in view

How to drop view in SQL Database
drop view viewName
drop view [vwEmpSocialNetwork]

Here you can see how to check dependency of any view, Just right click on view and then select "View Dependency"

You also can set permission of any view to particular user or user role,
Right Click => Select Properties

View in SQL Database

Group Training