Global temporary tables in SQL Server

后端 未结 3 1869
灰色年华
灰色年华 2020-12-07 03:00

I have a ##table which can be accessed across all the sessions but sometimes I am getting error

There is already an object named \'##table\' in the

3条回答
  •  青春惊慌失措
    2020-12-07 03:22

    So the WHY part has been answered and here is how to resolve it:

    Do a check to see if the temp table exists before creating it:

        if object_id('tempdb..##table') is null begin
            --create table ##table...
        end
    

    I found a pretty interesting post about how to check the existence of a temp table from Googling http://sqlservercodebook.blogspot.com/2008/03/check-if-temporary-table-exists.html

提交回复
热议问题