I need help on SQL!

  • I need help on the following queries, can anyone tell me what hypothetical execution plans these queries do??

     

    (1)SELECT *

    FROM TABLE;

    (2)SELECT COUNT(*)

    FROM TABLE;

    (3)SELECT S_SUPPKEY

    FROM TABLE;

    (4)SELECT *

    FROM TABLE

    WHERE S_NAME = 'User';

  • Without knowing HOW you set up the table (indexes, row count, etc..) it is impossible for us to even GUESS.

    However, IF you hit CTRL+L inside QA it will provide you an "estimated execution plan" OR CTRL+K and RUN the query it will provide the ACTUAL plan used



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Looking at my crystal I see:

    1) Table scan or Clustered Index Scan

    2) Scan of the narrowest index SQL Server can find. If no index present, I think table scan

    3) Index scan or clustered index scan.

    4) Index Seek or Clustered Index Seek.

    But as AJ pointed out, you can easily check this out yourself.

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Actually, I can answer for #2.

    If there's an index on the table on a column that is not nullable, then the query will scan that index to count all rows.

    If not suitable index is found, then a table scan will be performed.

  • Damn, got beaten again .

  • Sorry,

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • wow... the replies are fast!

     

    thanks alot guys, appreciated the helps.. will look tru the Ctrl + K

  • You're welcome!

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • 3 replies in 10 minutes... I've seen faster in this board .

  • What do you expect on a Friday afternoon?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • 5 replies in 2 minutes... we are less busy that time of the week .

  • heh, its actually 8.51pm at my place.. doing my assignment..

    actually... where do i press the ctrl + k at?? what QA??

     

    thanks all..

  • QA = Query Analyzer

    Paste the 4 queries in the window, then hit ctrl-k (or go in the query menu, and select show execution plan).

    Then run the queries (F5 or the green play button).

    Then under the results you'll see the execution plan tab.

  • where can I find the QA?

  • Start / All programs / Sql Server / Query Analyser

    You'll be prompted to login to a server.. select the server and enter login info as required. Then follow the previous steps.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply