用于清除 SQL 表的 Azure 数据存储管道

标签 azure azure-sql-database pipeline azure-data-factory purge

我想知道是否可以创建一个 Azure 管道并让它运行一个清除我的 Azure SQL 表的过程。

我对数据工厂的概念仍然很陌生,而且我发现数据工厂通常具有将数据从 blob 复制到 azure SQL/本地 SQL 或相反的管道。

我正在尝试编写一个数据工厂管道,它将清除我的 Azure SQL DB 中的旧记录,并希望是否有人能给我指出正确的方向。我仍然可以使用 Azure 数据工厂来实现此目的吗?

最佳答案

我的建议是使用 Azure Automation 而不是 ADF 来安排存储过程的执行。您会发现示例herehere 。以下是您需要在 Azure 自动化上实现的代码:

workflow NAME-OF-YOUR-WORKFLOW
{
    Write-Output "JOB START BEFORE INLINESCRIPT"

    inlinescript
    {
        Write-Output "JOB START"
        # Create connection to Master DB
        $MasterDatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
        $MasterDatabaseConnection.ConnectionString = "Data Source=YOUR-DATABASE-SERVER-NAME.database.windows.net;Initial Catalog=YOUR-DATABASE-NAME;Integrated Security=False;User ID=YOUR-DATABASE-USERNAME;Password=YOUR-DATABASE-PASSWORD;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"
        $MasterDatabaseConnection.Open()

        Write-Output "CONNECTION OPEN"

        # Create command
        $MasterDatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
        $MasterDatabaseCommand.Connection = $MasterDatabaseConnection
        $MasterDatabaseCommand.CommandText = "YOUR-PROCEDURE-NAME"

        Write-Output "DATABASE COMMAND TEXT ASSIGNED"

        # Execute the query
        $MasterDatabaseCommand.ExecuteNonQuery()

        Write-Output "EXECUTING QUERY"

        # Close connection to Master DB
        $MasterDatabaseConnection.Close() 

        Write-Output "CONNECTION CLOSED"
    }    
    Write-Output "WORK END - AFTER INLINESCRIPT"
}

要了解有关 Azure 自动化的更多信息,请单击 here .

希望这有帮助。

关于用于清除 SQL 表的 Azure 数据存储管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45756507/

相关文章:

创建 n 个 child ,每个 child 都有自己的管道

Azure CloudApp - 如何正确设置 CNAME DNS (NGINX)

azure - 如何将数组定义为应用程序设置的环境变量

sql-server - 如何检索日志以调查 Azure SQL Server 中删除的数据库用户?

sql - 无法删除 Sql Azure 上的表

gitlab - 如何在 GitLab CI 的管道中将变量值从一个作业传递到下一个作业?

c# - 从 Android 应用程序调用 Azure Web api 在等待响应时永远挂起

azure - 使用移动应用程序中的 AAD 自定义登录对 Azure 应用程序服务进行身份验证

azure - 分配给 SQL 数据库 Azure 的保留 IP 地址(经典)

Azure devOps 构建管道 : Force fail yaml step. bash 以防出现 isql 问题