Difference between #temptable and ##TempTable?

后端 未结 6 1261
臣服心动
臣服心动 2020-12-02 16:16

What is the difference between #temptable and ##TempTable in SQL Server?

6条回答
  •  生来不讨喜
    2020-12-02 17:14

    simple way of testing #localtable and ##globaltable

    Try this in a different SQL Query Window

    create table ##globaltemptable (id int )
    go
    insert into ##globaltemptable values (1)
    go
    select * from ##globaltemptable
    

    Try this in a different SQL Query Window

    create table #localtemptable (id int )
    go
    insert into #localtemptable values (1)
    go
    select * from #localtemptable
    

    Now if you run the select query for the table : #localtemptable in the global window syntax , you will get an error as follows :-

    Invalid object name '#localtemptable'.
    

    While you run the select query for the table : ##globaltemptable in any query window of the same session, you will get the query results return.

提交回复
热议问题