How to write SQL Insert Query in Yaml file using GitHub Actions?

Pulipati Vedanth 111 Reputation points
2021-07-20T10:28:34.513+00:00

Hi,

I am trying to insert data into My database tables which resides on Azure SQL Database using git hub action pipelines .connection strings are working fine .Need to Know how we write inset scripts of sql in yaml file. Any Reference links will be appreciated.

Thanks in advance.

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2021-07-20T21:29:47.347+00:00

    Hi @Pulipati Vedanth ,

    Thanks for using Microsoft Q&A !!
    If you want to execute any SQL Query through GitHub Actions then you can create a SQL Script file (with your SQL Insert statements) in your repository at root level and refer the SQL file using sql-file: attribute under azure/sql-action@v1 section of YAML. Once build is run, it will pick up the script file and execute it on the specific azure SQL server. Please refer to the below YAML snippet (Check line 23) for your reference.
    name: SQL for GitHub Actions

    on:  
     push:  
        branches: [ master ]  
     pull_request:  
        branches: [ master ]  
      
      
    jobs:  
      build:  
       runs-on: windows-latest  
       steps:  
        - uses: actions/checkout@v1  
        - uses: azure/login@v1  
          with:  
            creds: ${<!-- -->{ secrets.AZURE_CREDENTIALS }}  
          
        - uses: azure/sql-action@v1  
          with:  
           server-name: 'servername.database.windows.net'  
           connection-string: ${<!-- -->{ secrets.AZURE_SQL_CONNECTION_STRING }}  
           sql-file: './test_sql_script.sql'  
        # Azure logout   
        - name: logout  
          run: |  
               az logout  
    

    SQL Script file:
    116451-image.png

    Content:
    116461-image.png

    So, when the workflow runs it executes the SQL script file as shown below -
    116471-image.png

    Please let me know if you have any questions.

    Thanks
    Saurabh

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.