r/MSSQL • u/Livid-Cantaloupe1597 • Jan 02 '26
Temporary table like in oracle
Hello,
we switched to ms sql 2019 from oracle and i missing a feature oracle had and i cant figure out a workaround.
On oracle we could create a session based temporary table that stays permanent with a fixed name and could be linked an used via ODBC like an normal table. The only difference to a normal table was that the rows in the table exists only for the session. These table could be used by serveral users without problems, they only got their own records.
We were able to link needed tables and these temporary tables from oracle via ODBC with MS Access.
I cant find a similar solution or workaround in ms sql.
Is there no solution for this?
greetings
1
u/Oerthling Jan 02 '26
SQL Server has 2 kinds of temporary tables:
Local temp table is only visible within its session and automatically gets dropped by the end of session or earlier if it goes out of scope (end of a procedure). These have a single # as a prefix in their name:
CREATE TABLE #Example.(...
Global temp tables are visible to other sessions (subject to user permissions of course) and automatically get dropped at the end of session. Or more precise the last session referencing the table. So it can live beyond the session that originally created the global temp table. These use ## as prefix.
CREATE TABLE ##Example.(...
I'm not a fan of the global temp tables. Always caused trouble. You can always just use regular tables and manage the dropping yourself.
1
u/jshine13371 Jan 02 '26
I don't understand why a local temp table is any different than what you're describing what you used in Oracle?
1
u/7amitsingh7 Jan 12 '26
SQL Server has temporary tables, just like Oracle, but the syntax is a little different. Use a single # for a local temp table (only visible in your session) and ## for a global temp table (visible to all sessions while it exists). For example:
CREATE TABLE #MyTemp (ID INT, Name VARCHAR(100));
INSERT INTO #MyTemp VALUES (1, 'Alice'), (2, 'Bob');
SELECT * FROM #MyTemp;
The nice part is that local temp tables disappear automatically when your session ends, just like Oracle’s temporary tables. If you want it to persist across sessions, you’d need a global temp table (##MyTemp) or just a regular table in a dedicated schema. So basically, SQL Server gives you the same flexibility, just with a slightly different naming convention.