question

PulipatiVedanth-8342 avatar image
0 Votes"
PulipatiVedanth-8342 asked SaurabhSharma-msft commented

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered SaurabhSharma-msft commented

Hi @pulipativedanth-8342,

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.


image.png (20.1 KiB)
image.png (12.7 KiB)
image.png (29.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your inputs it worked for me @SaurabhSharma-msft

0 Votes 0 ·

@pulipativedanth-8342 - Great, thanks for the confirmation.

Thanks
Saurabh

0 Votes 0 ·