How do I bulk truncate tables using Azure Data Factory?

Christopher Lundy 1 Reputation point
2021-10-22T01:13:46.323+00:00

I want to make a pipeline or take an action to lookup all the tables in an Oracle database and truncate all of them iteratively. I don't want to copy data as we have pipelines for that but I do want to truncate all data.

How can I do that?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,487 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Shalvin 161 Reputation points
    2021-10-25T22:49:19.187+00:00

    Hi @Christopher Lundy

    I would give you a rather simple solution which can do the truncate in a single query single step.

    Get the list of tables to truncate comma separated using lookup / parameter etc.

    pipeline().parameters.tables = 'my_table1,my_table3,my_table3'  
    

    Create Truncate query by replacing , with ; TRUNCATE TABLE

    query = @concat('TRUNCATE TABLE ', replace(pipeline().parameters.tables, ',', ' CASCADE; TRUNCATE TABLE '), ' CASCADE;')  
    

    Run the query using an activity of your choice, eg. lookup.
    I am using this approach for SQL Sever. I am kind of confident that it will work everywhere.

    1 person found this answer helpful.
    0 comments No comments

  2. KranthiPakala-MSFT 46,422 Reputation points Microsoft Employee
    2021-10-22T16:54:59.627+00:00

    Hi @Christopher Lundy ,

    Welcome to Microsoft Q&A forum and thanks for reaching out here.

    In order to truncate the oracle table iteratively, then you will have to have place holder where you have a list of tables that you would want to take action. It could be either oracle table or a Azure Blob.

    Then you will have to use a Lookup activity to get the list of tables and then pass the output to ForEach activity and inside ForEach activity have another Lookup activity and write a query to truncate the table (the table name passed passed the current iteration of the ForEach activity as @item() ). But please make sure that your query return some result set as SUCCESS or FAIL so that the inner lookup activity doesn't fail. This is because lookup activity expects a response.

    Here is the reference doc: Lookup activity in Azure Data Factory and Azure Synapse Analytics

    Please Note: When you use query or stored procedure to lookup data, make sure to return one and exact one result set. Otherwise, Lookup activity fails.

    Hope this info helps. Do let us know if you have further query.

    ----------

    • Please don't forget to click on 130616-image.png and upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators