0

I'm looking at some production SQL scripts and I see some table names that start with a hash #. Like,

select * from #tmp

or

IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
    DROP table #tmp;

Does # have an actual meaning? Why use it?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Chuck
  • 749
  • 7
  • 32
  • 2
    The `#` indicates a temporary table in SQL Server. – Gordon Linoff Jul 30 '19 at 14:13
  • 1
    To add to what @GordonLinoff said, `#` denotes a `LOCAL` temporary table (visible in a single session, where it was created). `##` will denote a `GLOBAL` temporary table, visible in all sessions (to all users connected to SQL Server). It will basically be pretty much like a persisted table, available to all users, until the server gets restarted. After that, it's gone. – Radu Gheorghiu Jul 30 '19 at 14:15
  • 1
    You may find this helpful. https://stackoverflow.com/questions/2920836/local-and-global-temporary-tables-in-sql-server/2921091 – Isaac Jul 30 '19 at 14:15

0 Answers0