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
pmscorca
Post Patron
Post Patron

Looping to copy tables in a dynamic manner using T-SQL

Hi,

I need to copy several tables from a lakehouse to a warehouse and in order to accomplish a such task I'd like to implement a T-SQL stored procedure writing a dynamic loop.

Now, how I could do in a Fabric warehouse? Thanks

1 ACCEPTED SOLUTION
NandanHegde
Super User
Super User

In case of meta data driven farmework, you would need a config table to manage the list of lakehouse table you want to copy into warehouse.

Then you can query the lakehouse within the warehouse:

https://www.linkedin.com/pulse/querying-lakehouse-data-from-warehouse-microsoft-fabric-jovan-popovic

 

And using While loop, you can write a dynamic stored procedure to iterate over the table list and clone them within warehouse via EXECUTE keyword

 

example : Execute('Select * from table 1')

rather than select you can write the clone command




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

View solution in original post

4 REPLIES 4
NandanHegde
Super User
Super User

In case of meta data driven farmework, you would need a config table to manage the list of lakehouse table you want to copy into warehouse.

Then you can query the lakehouse within the warehouse:

https://www.linkedin.com/pulse/querying-lakehouse-data-from-warehouse-microsoft-fabric-jovan-popovic

 

And using While loop, you can write a dynamic stored procedure to iterate over the table list and clone them within warehouse via EXECUTE keyword

 

example : Execute('Select * from table 1')

rather than select you can write the clone command




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

Hi @pmscorca 

 

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.
In case if you have any resolution please do share that same with the community as it can be helpful to others.
Otherwise, will respond back with the more details and we will try to help.

 

Thank you.

Hi @pmscorca 

 

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others. If you have any question relating to the current thread, please do let us know and we will try out best to help you. In case if you have any other question on a different issue, we request you to open a new thread.

 

Thank you.

Hi @pmscorca 

 

Glad that your query got resolved.
Please continue using Fabric Community for further queries.

 

Thank you.

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!

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.

Top Solution Authors
Top Kudoed Authors