# SQL Security

## 🔗 What is SQL Security ?

The SQL Security allows you to restrict access of the survey to a given row of an existing SQL Server table and let you reuse the data from that query for piping purposes anywhere in your survey questions or answers using the [data attributes](https://docs.ngsurvey.com/form-management/security/data-attributes).\
\
Each query can be parametrized using entries from the respondent.  You can add new variables to build a user interface allowing the respondent to fill them up. These variable can then be used in your query as standard SQL parameters. <br>

![](https://1025048312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FWm2qhJO7BVPcAyEe84VV%2Fimage.png?alt=media\&token=495576c3-4291-400d-aef9-741418a31948)\
\
\
If you want to fill a variable based on a querystring you can create a variable of type  "Hidden" and pipe in its default a value from the querystring as shown below where a customer id is piped from the querystring "customerid" variable.

![](https://1025048312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FF1HC5DMKeWwuEGRD5uSK%2Fimage.png?alt=media\&token=c91b99df-810d-40a6-8187-09bca0adb3ff)

{% hint style="info" %}
If your user interface is composed using only hidden variable ngSurvey will automatically call the query once the survey gets loaded and no user interface will be shown.
{% endhint %}

{% hint style="warning" %}
Respondent will only be granted access if the query returns a row or if the **Access only to SQL entries** option is disabled.
{% endhint %}

Once the respondent has finished the survey and submitted his answers ngSurvey will save the retrieved SQL data along the respondent answers.

## 🔅 SQL Security properties

* **`Available Connections`** Connection that will be used to connect to your database
* **`SQL query`** SQL query or stored procedure call that will return the row and its column.&#x20;
* **`Allow multiple submissions`** lets the same row submit multiple times on the same survey. &#x20;
* **`Introduction message`** will be shown above the fields user interface when respondents tries to access the survey.
* **`Invalid key message`** error message shown to the user if no row is returned based on the entered value.

{% hint style="success" %}
This security item can be used as a [key provider](https://docs.ngsurvey.com/form-management/security/key-provider-concepts).&#x20;
{% endhint %}
