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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jpelham
Helper I
Helper I

How to add column to multiple tables

I am trying to add a date column to multiple tables that I am loading from our sql server. I have been able to add the date column when I only do one table within a copy data activity, but cannot figure out how to apply the column addition to multiple tables. I think the issue is related to the mapping and only being able to import one schema at a time. Is there a way to import schemas for all of the tables in the data load using a dynamic expression? 

3 ACCEPTED SOLUTIONS

It is not a calculated column that I am trying to add. I want to add a column for a date that the data was loaded, and also a column with the pipeline run ID. I can do this for one table easily in the copy data activity, but when loading more than one table, the copy data activity does not support that functionality. There are ways that I can do this through script activities and/or notebooks, but none of those are efficient for our use case. We have hundreds of tables on this specific sql server and won't be loading them all in the same pipeline, so it will be very tedious to do this for specific tables. I plan to make a suggestion for the functionality to be incorporated into the copy data activity. 

 

Thank you for the help though Houston-ho!

View solution in original post

I found a way to accomplish this. 

 

First you have to create some parameters for the pipeline:

jpelham_0-1726687401279.png

One is a list of the table names that you want to load and the other is to create the pipeline_RunID parameter for the pipeline_RunID column. The date column will be created in a different step, though you could do it here in a separate parameter if you wanted to use dynamic content like utcNow. 

 

Next you need to add the ForEach activity and include the followng code in the settings tab of the activity to reference the tableList parameter created in the previous step:

jpelham_1-1726687685879.png

 

Then add a Copy Data activity in the For Each Activity. Under the source tab you will connect to your sql server and the desired database. Select Query.

jpelham_2-1726687899464.png

In the query field enter this code, or similar depending on your use case:

SELECT *, GETDATE() AS load_date, '@{pipeline().RunId}' AS pipeline_RunID FROM @{item()}
 
On the destination tab connect to your desired lakehouse and enter @item() in the table field:
jpelham_3-1726688122180.png

 

View solution in original post

8 REPLIES 8
v-kongfanf-msft
Community Support
Community Support

Hi @jpelham ,

 


Did Houston-ho reply solve your problem? If so, please mark it as the correct solution, and point out if the problem persists.

 

Best regards,

Adamk Kong

 

 

Houston-ho
Advocate I
Advocate I

have you consider doing the "add column" steps after the copy activities?

and what is the sink for the copy? if that is SQL, you could run a stored procedures to update multiple tables at once.

I am taking tables from our on-prem sql server and loading them into a Fabric Lakehouse. How would I go about adding a column after the copy activity?

If you are talking about adding calculated column, use the notebook to create a new column on your lakehouse table. This video is quite good.
https://youtu.be/2RuoHpNZbc4

It is not a calculated column that I am trying to add. I want to add a column for a date that the data was loaded, and also a column with the pipeline run ID. I can do this for one table easily in the copy data activity, but when loading more than one table, the copy data activity does not support that functionality. There are ways that I can do this through script activities and/or notebooks, but none of those are efficient for our use case. We have hundreds of tables on this specific sql server and won't be loading them all in the same pipeline, so it will be very tedious to do this for specific tables. I plan to make a suggestion for the functionality to be incorporated into the copy data activity. 

 

Thank you for the help though Houston-ho!

I found a way to accomplish this. 

 

First you have to create some parameters for the pipeline:

jpelham_0-1726687401279.png

One is a list of the table names that you want to load and the other is to create the pipeline_RunID parameter for the pipeline_RunID column. The date column will be created in a different step, though you could do it here in a separate parameter if you wanted to use dynamic content like utcNow. 

 

Next you need to add the ForEach activity and include the followng code in the settings tab of the activity to reference the tableList parameter created in the previous step:

jpelham_1-1726687685879.png

 

Then add a Copy Data activity in the For Each Activity. Under the source tab you will connect to your sql server and the desired database. Select Query.

jpelham_2-1726687899464.png

In the query field enter this code, or similar depending on your use case:

SELECT *, GETDATE() AS load_date, '@{pipeline().RunId}' AS pipeline_RunID FROM @{item()}
 
On the destination tab connect to your desired lakehouse and enter @item() in the table field:
jpelham_3-1726688122180.png

 

If you make a suggestion (Idea) please post a link to the Idea here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.