{"id":1085,"date":"2021-02-08T02:31:46","date_gmt":"2021-02-08T02:31:46","guid":{"rendered":"http:\/\/jackofalltradesmasterofsome.com\/blog\/?p=1085"},"modified":"2021-02-10T20:54:22","modified_gmt":"2021-02-10T20:54:22","slug":"looping-sql-tables-to-data-lake-in-azure-data-factory","status":"publish","type":"post","link":"http:\/\/jackofalltradesmasterofsome.com\/blog\/2021\/02\/08\/looping-sql-tables-to-data-lake-in-azure-data-factory\/","title":{"rendered":"Looping SQL Tables to Data Lake in Azure Data Factory"},"content":{"rendered":"\n<p>When you load data from a SQL Server, instead of individual pipelines, it is best to have one dynamic table controlled process. Learn how to loop through SQL tables dynamically to load from SQL Server to Azure Data Lake. Looping SQL Tables to Data Lake in Azure Data Factory<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up the ETL_Control Database<\/h2>\n\n\n\n<p>Create the database ETLControl and the table to store the metadata for the ETL runs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USE &#91;ETLControl]\nGO\n\nSET ANSI_NULLS ON\nGO\n\nSET QUOTED_IDENTIFIER ON\nGO\n\nCREATE TABLE &#91;dbo].&#91;ETLControl](\n\t&#91;Id] &#91;int] IDENTITY(1,1) NOT NULL,\n\t&#91;DatabaseName] &#91;varchar](50) NOT NULL,\n&#91;SchemaName] &#91;varchar](50) NOT NULL,\n\t&#91;TableName] &#91;varchar](50) NOT NULL,\n\t&#91;LoadType] &#91;varchar](50) NOT NULL\n) ON &#91;PRIMARY]\nGO\n\n\nInsert Into &#91;dbo].&#91;ETLControl]\nSelect 'Databasename', 'dbo', 'TableName1', 'Full'\n\nInsert Into &#91;dbo].&#91;ETLControl]\nSelect Dataasename', 'dbo', 'TableName2', 'Full'\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Azure Data Factory<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a Linked Service to the SQL Database <\/li><\/ol>\n\n\n\n<ul class=\"wp-block-list\"><li>Create a DataSet for the ETLControl Database<ul><li>Point to the Linked Service for SQL Server<\/li><\/ul><ul><li>Do no assign it a table name. This will be done dynamically later.<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"176\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-1.png\" alt=\"\" class=\"wp-image-1088\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-1.png 574w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-1-300x92.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Add a new Pipeline with the Lookup object<ul><li>Set the source Query\u00a0 \u201cSelect * From ETLControl\u201d<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"299\" height=\"268\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-2.png\" alt=\"\" class=\"wp-image-1089\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Add the For Each Loop<ul><li>In the settings add the Dyanmic Item \u201c@activity(&#8216;Get-Tables&#8217;).output.value\u201d<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"482\" height=\"282\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-3.png\" alt=\"\" class=\"wp-image-1090\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-3.png 482w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-3-300x176.png 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Add a new data source for the SQL Souce<ul><li>Give the SQL a parameter for TableName and SchemaName<\/li><\/ul><ul><li>Update the Table to use the variables<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"217\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-4.png\" alt=\"\" class=\"wp-image-1091\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-4.png 588w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-4-300x111.png 300w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"179\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-5.png\" alt=\"\" class=\"wp-image-1092\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-5.png 624w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-5-300x86.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Add a new data source for the DataLake Destination<ul><li>Give the SQL a parameter for FileName<\/li><\/ul><ul><li>Update the File Path to the Dynamic content parameter<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"142\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-6.png\" alt=\"\" class=\"wp-image-1093\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-6.png 546w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-6-300x78.png 300w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"82\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-7.png\" alt=\"\" class=\"wp-image-1094\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-7.png 624w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-7-300x39.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Add a Copy Activity to the For Each Loop.<ul><li>Set the source using the variables from the Lookup<\/li><\/ul><ul><li>Set the sink as the file name variable from look up with .csv<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"153\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-8.png\" alt=\"\" class=\"wp-image-1095\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-8.png 496w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-8-300x93.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"486\" height=\"182\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-9.png\" alt=\"\" class=\"wp-image-1096\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-9.png 486w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-9-300x112.png 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Debug to run to see new files land in Data Lake with dynamic names. There should be one file for each table that was loaded. You can modify the file names to include folder names and more dynamic storage if needed.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"115\" src=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-10.png\" alt=\"\" class=\"wp-image-1097\" srcset=\"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-10.png 624w, http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-content\/uploads\/2021\/02\/image-10-300x55.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p>Looping SQL Tables to Data Lake in Azure Data Factory<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you load data from a SQL Server, instead of individual pipelines, it is best to have one dynamic table controlled process. Learn how to loop through SQL tables dynamically to load from SQL Server to Azure Data Lake. Looping SQL Tables to Data Lake in Azure Data Factory Setting up the ETL_Control Database Create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,97,28,27,11,1],"tags":[],"class_list":["post-1085","post","type-post","status-publish","format-standard","hentry","category-analytics","category-automation","category-azure","category-big-data","category-data-warehouse","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/comments?post=1085"}],"version-history":[{"count":2,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1085\/revisions"}],"predecessor-version":[{"id":1099,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/posts\/1085\/revisions\/1099"}],"wp:attachment":[{"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/media?parent=1085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/categories?post=1085"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jackofalltradesmasterofsome.com\/blog\/wp-json\/wp\/v2\/tags?post=1085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}