I am using Oracle 11g Global Temporary Tables as I need a solution where I can add rows to a temporary table for a join, and I want only the rows added to the temp table for the Oracle Connection/session to be included. I am using Global Temp Table in Oracle becuase I want the table to exist between sessions so it doesn't have to be recreated every time I create a query. This is working out fine.
My Oracle table definition is as follows:
CREATE GLOBAL TEMPORARY TABLE book_id_temp
(
book_id RAW(32)
)ON COMMIT DELETE ROWS;
I have the same database structure also on the SQL Server 2008-R2 side, and need a similar solution in SQL Server. I want to :
- Open a SQL Connection (ADO.NET)
- Within a Transaction:
- -Add rows to a temp table.
- -Join them on another table, SELECT the results
- -Have only the rows added during this session be included in the join. Another thread may be executing on the same temporary table. It's possible then that a local temp table would be best here?
- Rollback the entire transaction.
From what I've read of global temporary tables in SQL Server, the tables exist after a connection is ended, like a regular table, and like a Global Temp Table in Oracle. However, it's not clear on the scope of the data. Does only the SQL Server session that created the rows have access to it, like in Oracle? What is the accessability of the data with SQL Server Global Temp Tables? Do you have a suggestion of an alternative to achieve my goal?