Sql-server – SSMS 2012 mutiple query windows using same session

sql serverssmstemporary-tables

I wonder if it is possible to connect multiple files or query windows in SSMS to one session? The reason is that I want to use local temporary tables that are created in one file/query-window in other file/query-windows. As local temporary tables have session scope this seems to be the only way to achieve this.

We use the temp tables for separating session data in our application. I use SSMS for development and in the development context it would be useful to have the same tmp tables available in multiple SSMS windows.

What i do now is copy the creation code of the tmp tables in all query windows, then evaluate that part and then cut them out again. So they are avaible in that session, but that's a bit cumbersome. So basically it is an SSMS question and not a SQL Server question.

Best Answer

It is not possible to share a local temporary table between connections.

Local temporary tables are scoped to a single session, but global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

Global temporary tables have two number signs (##) as the first characters of their names, for example:

CREATE TABLE ##GlobalTemp
(
    c1 integer NULL
);