How to create views in Sql Server

A view is a stored sql query is made readily available in a usable format.
A view can have Joins,aggregate functions,Where clause.

 

Use the following command to create a view from the database

CREATE dbo.ViewName

AS

Your T-SQL Select Statement

 

Use the following command to alter a view from the databaseALTER dbo.ViewName

ALTER dbo.ViewName

AS

Your T-SQL Select Statement

 

Use the following command to remove a view from the database

DROP VIEW dbo.ViewName

 

Use the following command Create or Alter a view from the database (like Oracle Create or Alter)

IF EXISTS(SELECT * FROM SysObjects WHERE Name = 'dbo.ViewName')

  DROP VIEW dbo.ViewName

CREATE  dbo.ViewName

AS

Your T-SQL Select Statement

 

Use the following command to query against a view

SELECT LastName, FirstName, City, ZipCode

   FROM dbo.ViewName   ORDER BY LastName, FirstName

 

Prefer using ALter instead of CREATE and ALTER, because dropping an existing view will remove the security permissions associated with it.

Alternate Titles: Create View, Drop View, Create Or Alter View, Use T-Sql View, Query against a View, Using View in a SQL Statement