Reputation: 768
I have a basic logic app with sql Inserting records and it works fine. but here I need to truncate table before insert records.
Is this possible with Azure logic apps? if so how can i achieve this?
Note: I am accessing DB using on-premises data gateway and database is MSsql one
Upvotes: 1
Views: 1056
Reputation: 22419
I need to truncate table before insert records. Is this possible with Azure logic apps?
Yeah you can do it on Logic App with out writing any SP.
There is builtin connector under SQL that is Execute a SQL Query
on logic app designer. You have to use that connector.
If so how can i achieve this?
You can write RAW
sql command there. See the below example.
I have a table like below:
CREATE TABLE AzureSqlTable(
[Id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](max) NULL,
[LastName] [nvarchar](max) NULL,
[Email] [nvarchar](max) NULL,
)
GO
Your Case:
In your case I had tried to
INSERT
data usingSQL
Executor command before INSERT operation I just TRUNCATE that table Like below:
TRUNCATE TABLE AzureSqlTable
INSERT INTO AzureSqlTable VALUES('PassFirstNameParam','PassLastNameParam','PassEmailParam')
I have defined a HTTP Request JSON schema with my parameter value and pass it to the SQL Executor Connector
. See the screen shot below:
On Premises Operation:
For on premises query execution you have to configure like below:
Note: For On Prem connection configuration you could refer this official docs
This is how you could can TRUNCATE your table before INSERT operation. As you already know how to configure SQL connection. So I haven't put that in.
Upvotes: 2
Reputation: 1984
Write a stored procedure on the SQL server that truncates the table, call upon that in logic apps via the SQL connector through the data gateway. After that, you could inject the data.
Upvotes: 0