22

Possible Duplicate:
What are views good for?

I'm trying to figure out what the purpose of views in an SQL database is?

Why, when and how would I create and use views?

Community
  • 1
  • 1
Johan Alkstål
  • 5,225
  • 9
  • 36
  • 48

2 Answers2

13
  • Many different perspectives of the same table.

  • Can hide certain columns in a table. For example you may want to allow employees to see other employees' phone number column, but only certain employees to be able to access an employee's salary column!

  • Can provide huge time savings in writing queries by already having a group of frequently accessed tables joined together in a view.

  • Views allow you to use functions and manipulate data in ways that meet your requirements. For example, you store a person's birth date, but you like to calculate this to determine their age.

Aasmund Eldhuset
  • 37,289
  • 4
  • 68
  • 81
Yada
  • 30,349
  • 24
  • 103
  • 144
3

It can be used to simplify complex joins that you use repeatedly across your DB.

CREATE view [dbo].[V_MyComplexJoin] 
As    
    Select TableA.A, TableB.B
    From TableA
        Inner Join TableB On TableA.BID = TableB.ID  
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157