How to Rename View in SQL Server 2008

In this article, I describe Views in SQL Server.
  • 4765

View

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 rename view in SQL Server 2008. To rename view we use stored procedure. 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

select * from vendors

Output:

Table-in-sql.jpg

Creation of a simple view:

create view vendorinfo

as

select vendorid,vendorname

from vendors

where vendorcity='noida'

A Statement that show data in view

select * from venderinfo

Output:

View-in-sql.jpg

Renaming:

exec sp_rename 'vendorinfo','v1'

Output:

RenameView-in-sql.jpg

© 2019 DotNetHeaven. All rights reserved.