How to Modify And Drop View in SQL
In this article I am going to explain how to modify and drop view in SQL.
Introduction
View in SQL is a virtual table and this table is created on the result set of SQL statement. View is similar to a normal table and also have rows and columns. View may be combination of some rows and columns of two or more than two tables. You can use SQL function and WHERE clause with View in SQL statement.
You can modify and drop view in SQL. To modify view we use ALTER VIEW statement. To delete view we use DROP clause. To create view we use CREATE VIEW statement with WHERE clause.
A Statement that create vendors table
create table vendors
(
vendorid int,
vendorname varchar(15),
vendorcity varchar(15),
vendorstate varchar(15)
)
|
Statements that insert data in vendors table
insert into vendors values (20,'vipendra','noida','up')
insert into vendors values (21,'deepak','lucknow','up')
insert into vendors values (22,'rahul','kanpur','up')
insert into vendors values (23,'malay','delhi','delhi')
insert into vendors values (24,'mayank','noida','up')
|
A Statement that is used to fetch data from vendors table

A Statement that is used to create a view in SQL
create view vendorinfo
as
select vendorid,vendorname
from vendors
where vendorcity='noida'
|
A Statement that show data in view

A Statement that is used to alter a view in sql
alter view vendorinfo
as
select vendorid,vendorname
from vendors
where vendorstate='up'
|
A Statement that show data in view after modification of view

A Statement that drop a view