Forum Discussion
kuladeep127
Mar 05, 2024Copper Contributor
Dynamically switch databases and create their views from deltalake
Hello Comminity, I am a newbie to Synapse. I need your help with a task I've been working on for a few days. I want to create views in SA for my delta tables from Deltalake. I have the below f...
kuladeep127
Mar 06, 2024Copper Contributor
I solved it.
After creating the database, I simultaneously create a stored procedure with the following code. The key aspect here is that I made the linked service itself dynamic for databases:
CREATE OR ALTER PROC CreatesQLserverlessView_gold @DatabaseName VARCHAR(100), @ViewName VARCHAR(100) AS BEGIN DECLARE @statement NVARCHAR(MAX) -- Switch the database context SET @statement = N'USE ' + @DatabaseName + ';' EXEC (@statement) -- Create or alter the view SET @statement = N'CREATE OR ALTER VIEW ' + @ViewName + N' AS SELECT * FROM OPENROWSET ( BULK ''https://keveebimdata.dfs.core.windows.net/gold/' + @DatabaseName + N'/' + @ViewName + '/'', FORMAT = ''DELTA'' ) AS [result]' EXEC (@statement) END
ADF pipeline where create database and a stored procedure for it:
Then, in my Synapse environment, I trigger the stored procedure for each table. Since each database already has the stored procedure within it, I simply need to switch the database at the linked service level. Subsequently, the stored procedure creates views for each delta table within their respective databases.
Pipeline trigger the stored procedure in synapse to create views for each database: