In this blog describe the concept of sql view in sql server. SQL view is a virtual table. Here we give simple example of view.
A View is a Virtual Table. It is not like a simple table, but is a virtual table which contains columns and data from different tables (may be one or more tables). A View does not contain any data, it is a set of queries that are applied to one or more tables that is stored within the database as an object. Once you have defined a view, you can reference it like any other table in a database.
Views are used for security purposes because they provide encapsulation of the name of the table. Data is in the virtual table, not stored permanently. Views display only selected data.
CREATE VIEW <view name>
Here we create the table of department and employee.
create table Departments(
DepartID int identity(1,1) primary key,
create table Employee(
EmpID int identity(1,1) primary key,
DepartID int references Departments(DepartID)
This is an example is a example of simple view which contain only one table.
CREATE VIEW ShowEmployeeData
SELECT * FROM Employee
SELECT * FROM ShowEmployeeData
This is an example for multiple table using join. It is also known as complex view.
CREATE VIEW ShowEmployee
SELECT e1.FirstName,e1.LastName,e2.DepartmentName FROM Employee e1 INNER JOIN Departments e2
ON e1.DepartID = e2.DepartID