Pound sign (#)

  • There doesn't seem to be any basic search for the forums so if this has been covered before, I appologize. I am very new to SQL Server (and db admin for that matter).

    What is the # used for? The following statement is why I'm asking this question:

    select name into #d

    from sysusers

    Does it represent a dummy table? A column in a dummy table?

    Thanks in advance,

    Chrys

  • it puts the results of the query into a temporary table name #d

  • Favorite temp table name... #MyHead 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hi Chrys204,

    This is the temporary table (#d) and it is for current session only. that means for the current query window. moreover this is the local temporary table.

    😉

  • Favorite temp table name... #MyHead

    I guess its not just me!! 😉

  • And then there are global temp tables that start with 2 pound signs (##d). These tables are available to any connection using the database so long as there are still connections. Once all the connections are closed, the global temp table is destroyed.

    So if I'm connected to MyDB and create ##SillyTempTable, so long as I haven't dropped the table and am still connected, one of my coworkers can connect to MyDB and access ##SillyTempTable also. If I disconnect while coworker is using the table, the table still stays in effect (or should according to MS). But once coworker disconnects (assuming no one else has connected to use it), then the table "vanishes" for good.

    Read up in BOL, subject "temporary tables".

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • "#MyHead "

    Thanks Jeff, for this morning's smile...

  • Jeff Moden (1/8/2008)


    Favorite temp table name... #MyHead 😀

    Pretty close to accurate too - disconnect the session and the table gets wiped:)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

Viewing 9 posts - 1 through 8 (of 8 total)

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