How to create global temporary table in Sqlserver.

Total Post:341

 911  View(s)
Rate this:
Can anyone please help me how to solve this problem.
  1. Post:282

    Re: How to create global temporary table in Sqlserver.

    SQL Server provides the concept of temporary table which helps the developer in a best way. These tables can be created at runtime and can do the all kinds of operations that one normal table can do. But, based on the table types, the scope is limited. These tables are created inside tempdb database. Global Temporary tables name starts with a double hash ("##"). Once this table has been created by a connection, like a permanent table it is then available to any user by any connection. It can only be deleted once all connections have been closed.

     --step 1 create global temporary table

    CREATE TABLE ##globaltemptbl( 

    OrderID int, rderdate datetime, amount decimal(10,2)


    --step-2 insert data in #globaltemptabl from order table

    insert into ##globaltemptbl select * from [Order]

    --step-3 select data from #globaltemptabl

    select * from ##globaltemptbl

      Modified On Apr-10-2018 05:01:39 AM