locked
Diff bet View Vs Select in sql server RRS feed

  • Question

  • Hi  ,

    Can anyone tell me what is the difference bet View & Select statement in sql server .



    Thanks.

    Friday, October 2, 2009 11:37 AM

Answers

  • Hi Vishal

    A View is basically a pre-defined and stored SELECT statement.

    It can get more advanced, but at a basic level they are the same.

    HTH

    Ewan

    If you have found this post helpful, please click the 'Vote as Helpful' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered' link below. It helps others who experience the same issue in future to find the solution.
    Friday, October 2, 2009 11:39 AM
  • Ewan is correct in his statement above, but let me go a bit further and say it really depends on how you use the view.  A view can be used to allow for cleaner code since you query from a view just as you would from a table.  However, you have to be careful with this because it is common for beginners to SQL Server to create nested views, which are views that are built using other/existing views.  Nested views can be bad for performance depending on the level of nesting and the complexity of the nesting.  When a view is parsed by SQL Server, it is expanded using its parse tree and nested views can result in really large redundant parse trees, which cause the same physical tables to be read unnecessarily.


    Jonathan Kehayias
    http://sqlblog.com/blogs/jonathan_kehayias/
    http://www.twitter.com/SQLSarg
    http://www.sqlclr.net/
    Please click the Mark as Answer button if a post solves your problem!
    Saturday, October 3, 2009 2:31 AM

All replies

  • Hi Vishal

    A View is basically a pre-defined and stored SELECT statement.

    It can get more advanced, but at a basic level they are the same.

    HTH

    Ewan

    If you have found this post helpful, please click the 'Vote as Helpful' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered' link below. It helps others who experience the same issue in future to find the solution.
    Friday, October 2, 2009 11:39 AM
  • Ewan is correct in his statement above, but let me go a bit further and say it really depends on how you use the view.  A view can be used to allow for cleaner code since you query from a view just as you would from a table.  However, you have to be careful with this because it is common for beginners to SQL Server to create nested views, which are views that are built using other/existing views.  Nested views can be bad for performance depending on the level of nesting and the complexity of the nesting.  When a view is parsed by SQL Server, it is expanded using its parse tree and nested views can result in really large redundant parse trees, which cause the same physical tables to be read unnecessarily.


    Jonathan Kehayias
    http://sqlblog.com/blogs/jonathan_kehayias/
    http://www.twitter.com/SQLSarg
    http://www.sqlclr.net/
    Please click the Mark as Answer button if a post solves your problem!
    Saturday, October 3, 2009 2:31 AM
  • Thanks Ewan. 

    it simplifies the tearms vary well . 

     
    Monday, October 5, 2009 11:39 AM
  • Hi Vishal

    Can you mark any helpful posts, and any that have answered your question. It helps keep the forums tidy.

    Regards

    Ewan

    If you have found this post helpful, please click the 'Vote as Helpful' link (the green triangle and number on the top-left).

    If this post answers your question, click the 'Mark As Answered' link below. It helps others who experience the same issue in future to find the solution.
    Monday, October 5, 2009 12:05 PM