# Stored procedures

With the stored procedure provider it is possible to call a stored procedure in one of your databases when a record is created, updated, deleted or when a data import has been done. &#x20;

{% content-ref url="/pages/XZKjQcL0C0ZGEhDLEA1V" %}
[Tutorial (video)](/writebackextreme/v5.0/product-guide/management-console/schemas/workflows/tutorial-video.md)
{% endcontent-ref %}

On the bottom you can find the actual statement that will be executed on the database when the workflow is triggered. The Try now button on the top right will execute this statement directly to test the execution.&#x20;

When the try button does not return an error the stored procedure is executed successfully.

<figure><img src="/files/R0Ju90EIYRdYRzuUCVlq" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
For SQL Server it is important that the name of the fields matches the name of the input parameters of your stored procedure

For other databases like MYSQL or PostgreSQL the sequence of the fields matter. As the example in the management console displays, the fields will be sent in the order of the list.
{% endhint %}

## Example in Postgresql

In this example we create a stored procedure that will consume 4 fields (user, status, accountmanager and sales\_amount. It will write this data to a table \`stored\_procedure\_data\`.

<pre><code>CREATE TABLE
  public.stored_procedure_data (
    id SERIAL,
    "user" character varying(255) NULL,
    status character varying(255) NULL,
    accountmanager character varying(255) NULL,
    sales_amount character varying(255) NULL,
    created_at timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
  );
  
CREATE OR REPLACE procedure <a data-footnote-ref href="#user-content-fn-1">MyStoredProcedure</a>(
   "user" character varying,
   "status" character varying, 
   "sales" character varying,
   "name" character varying
)
language plpgsql    
as $$
begin
    INSERT INTO stored_procedure_data ("user", "status", "accountmanager", "sales_amount") 
    VALUES ("user", status, name, sales);
    commit;
end;$$
</code></pre>

## Example in MySQL

```
CREATE TABLE
  stored_procedure_data (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `user` VARCHAR(255) NULL,
    `status` VARCHAR(255) NULL,
    `accountmanager` VARCHAR(255) NULL,
    `sales_amount` VARCHAR(255) NULL,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELIMITER //
CREATE PROCEDURE MyStoredProcedure (
  IN user VARCHAR(255),
  IN status VARCHAR(255),
  IN sales VARCHAR(255),
  IN name VARCHAR(255)
)
BEGIN    
     INSERT INTO stored_procedure_data (`user`, `status`, `accountmanager`, `sales_amount`) 
    VALUES (user, status, name, sales);
END //
DELIMITER ;
```

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.infotopics.com/writebackextreme/v5.0/product-guide/management-console/schemas/workflows/stored-procedures.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
