Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    4

    Unanswered: View selection question

    Ive got a question relating to how a view selects data from an underlying table.


    If there is a table called person and it looks like this:
    PersonID
    Last Name
    FirstName

    I create a view off of the table like this:

    Create View Person_View as
    Select
    PersonID,
    Last Name,
    FirstName,
    From Person

    And I write a query like this

    Select PersonID from Person_View

    How does this get translated to the table?

    Does the view select all three columns even though I specified one column in the query?

    BTW, this is SQL Server 2005 if it makes a difference.

    Thanks!

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The sql code for the view is folded into the overall sql code for the your statement, prior to it being optimized. So in this case, the optimizer would likely ignore the columns not specifically referenced.

    Why does this make a difference to you? Are you just concerned about the width of the data rows returned?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2005
    Posts
    4
    Quote Originally Posted by blindman
    The sql code for the view is folded into the overall sql code for the your statement, prior to it being optimized. So in this case, the optimizer would likely ignore the columns not specifically referenced.

    Why does this make a difference to you? Are you just concerned about the width of the data rows returned?
    Well I just made up a quick example. The view that Im going to be querying against has 48 columns and I want to make sure that if I only selected 10 columns from a view, that it doesnt select all 48 (fro the table) and only display the 10 I selected.

    Thanks for the reply.

  4. #4
    Join Date
    Jun 2004
    Location
    Philly
    Posts
    51
    after you get everything created you can run that query against query optimizer and see if there are any indexes that you can create to make it run faster

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •