Database Views Introduction

← Go back to Database Chapter

Views are a logical entity which act as a mask on the table.

Views will be created based on the table by fetching the data from the table, but the view does not contain the data physically. When view needs the data, it will get it from the table.

Create view view_name Select statement;

create table students(
studentid int primary key auto_increment not null, studentname varchar(32) not null,
email varchar(32) not null, phone int not null,
feepaid int, feebalance int, jobstatus varchar(32));

Studentviews in sql


    admin mg - email, phone
    Account mgr - Student ID, Fee Paid, Fee Balance
    HR mgr - Student ID, Student name, email, phone, job status


    create view admin as
    select email

views in sql


    create view accountmanager as
    select studentid, feepaid, feebalance from students;

views in sql


    select studentid, studentname, email, phone, jobstatus from students;

views in sql


  1. Increase the security levels

  2. Decreases redundancy


  1. Static views

  2. Dynamic views

Static Views:

  • Static views also called as read only views

  • We cannot perform insert, update and delete operations on static views

Dynamic Views:

  • Dynamic views are also called updatable views

  • You can perform select, insert, update and delete operations on the updatable views or in the dynamic views

Create index i2 on accounts (branch code, account type, account no.);
Sr. No Select state of view Static View Dynamic View
1. Contains primary key - .
2. Does not contain a primary key . -
3. Contains aggregate functions . -
4. Does not contain agg format - .
5. Contains group by . -
6. Does not contain group by - .
7. Contain joins . -
8. Does not contain join - .


    create table hello(id int primary key auto_increment not null,a int, b int, c int);

Table helloviews in sql

create view v1 as
select sum(a) from hello;

views in sql