Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DominilMs
Frequent Visitor

Temp table not working in Pipeline Script activities

Hello, I cannot find inforamtion why such code works

DECLARE @Temp TABLE ( sCode VARCHAR(30))  INSERT INTO @temp ( sCode ) VALUES ('1'); select top 1 * from @Temp
and this one give me error that #temp table do not exist
DROP TABLE IF EXISTS #temp CREATE TABLE #temp ( sCode VARCHAR(30) ) INSERT INTO #temp ( sCode ) VALUES ('1') select * from #temp

Failure happened on 'Source' side. ErrorCode=SqlOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=A database operation failed with the following error: 'Invalid object name '#temp'.',Source=,''Type=System.Data.SqlClient.SqlException,Message=Invalid object name '#temp'.,Source=.Net SqlClient Data Provider,SqlErrorNumber=208,Class=16,ErrorCode=-2146232060,State=0,Error

I'm trying to run Script activites in Microsoft Fabric pipeline

1 ACCEPTED SOLUTION
v-pnaroju-msft
Community Support
Community Support

Hi DominilMs,

Thank you for your follow-up.

The problem you are facing happens because temporary tables (like #temp) in Microsoft Fabric are only available within the current session. Even though the operations are done in the same Script activity, Fabric may treat them as separate sessions. This causes the #temp table to disappear and gives the error "Invalid object name '#temp'."

Please follow these steps to fix the issue:

  1. Use permanent tables instead of temporary ones. Permanent tables are saved in your Lakehouse or Data Warehouse and can be used across different activities. This way, you will not have session-related issues. Permanent tables stay available in all sessions and activities, so the tables won’t disappear.

  2. If you don’t want to use permanent tables and your work is in only one Script activity, use table variables (like @temp). These variables work only during the execution of that activity.

If you have any more questions, please feel free to ask the Microsoft Fabric community.

Thank you.

View solution in original post

6 REPLIES 6
v-pnaroju-msft
Community Support
Community Support

Hi DominilMs,

Thank you for your follow-up.

The problem you are facing happens because temporary tables (like #temp) in Microsoft Fabric are only available within the current session. Even though the operations are done in the same Script activity, Fabric may treat them as separate sessions. This causes the #temp table to disappear and gives the error "Invalid object name '#temp'."

Please follow these steps to fix the issue:

  1. Use permanent tables instead of temporary ones. Permanent tables are saved in your Lakehouse or Data Warehouse and can be used across different activities. This way, you will not have session-related issues. Permanent tables stay available in all sessions and activities, so the tables won’t disappear.

  2. If you don’t want to use permanent tables and your work is in only one Script activity, use table variables (like @temp). These variables work only during the execution of that activity.

If you have any more questions, please feel free to ask the Microsoft Fabric community.

Thank you.

Hi:

 

Since our organization has a lot of exisiting T-SQL queries for existing reports that our customers are running all the time, does Microsoft Fabric have a ETA date that they will actually fix this temp table issue or do we have to convert all of our queries to use the proposed solutions here?  Amazon RDS for SQL Server supports temporary tables: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.TempDB.html  and Google Cloud also supports temporary tables.  https://cloud.google.com/sql/docs/sqlserver/features 

I guess without any ETA of when this issue can be resolved in Fabric, I would have to think about other options like AWS and Google cloud as alternatives?  Since it would take a lot of time to make these changes. Thanks,

Thank you

v-pnaroju-msft
Community Support
Community Support

Thankyou, @nilendraFabric, for your response.

Hi DominilMs,

We appreciate your question on the Microsoft Fabric Community Forum.

From what I understand, @Temp TABLE refers to table variables, which are limited to the current batch or block of the script. This means they work only inside a single Script activity if all operations happen within that same script. On the other hand, #Temp TABLE are temporary tables that only exist for the current SQL session.

In Microsoft Fabric Pipelines, every Script activity runs in its own separate session. Because of this, the #Temp table created in one activity or statement is not accessible in the next activity, even if it is inside the same pipeline. This is why you see the error: 'Invalid object name '#temp'.'

To keep data available across different activities or to avoid this problem, please follow the steps below:

  1. Use permanent tables by creating a normal table in your Lakehouse or Warehouse for temporary data. Permanent tables stay available across sessions, so you will not face the scope problem.
    DROP TABLE IF EXISTS dbo.TempStorage;
    CREATE TABLE dbo.TempStorage (sCode VARCHAR(30));
    INSERT INTO dbo.TempStorage (sCode) VALUES ('1');
    SELECT * FROM dbo.TempStorage;
  2. If you prefer to use temporary structures like @Temp, make sure all related operations (creation, insert, and select) happen inside one script only. This works because @Temp is available only during the execution of one activity.
    DECLARE @Temp TABLE (sCode VARCHAR(30));
    INSERT INTO @Temp (sCode) VALUES ('1');
    SELECT * FROM @Temp;

If you find this response helpful, please mark it as the accepted solution and give kudos. This will help other community members facing the same problem.

If you have any more questions, please feel free to ask the Microsoft Fabric community.

Thank you.

Thanks for your response


@v-pnaroju-msft wrote:

Thankyou, @nilendraFabric, for your response.

In Microsoft Fabric Pipelines, every Script activity runs in its own separate session. Because of this, the #Temp table created in one activity or statement is not accessible in the next activity, even if it is inside the same pipeline. This is why you see the error: 'Invalid object name '#temp'.'

 


The problem is that all these #temp table instructions are in the same activities in the same Script, thats why I can't understand why it doesn't work 

 

nilendraFabric
Super User
Super User

Hi @DominilMs 


Each pipeline activity runs in a separate session. Since `#temp` tables are session-scoped, they become inaccessible across activities, causing “Invalid object” errors.
Example: Your `#temp` table fails in Script Activity because the entire pipeline doesn’t share a single session

 

DECLARE @Temp TABLE` succeeds because it’s batch-scoped, not session-dependent. It remains valid within a single activity’s execution context.

For multi-activity workflows or large data, use physical tables. They persist across sessions and avoid isolation issues.

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.