The SQL UPDATE query is used to modify the existing record(s) in a database table.
Let's assume we are changing the name of the specific person in our actors database table.
The SQL syntax of UPDATE query is:
Here we select specific records with the help of WHERE condition, and set new value 'Kaley Cuoco-Sweeting' in the name column for all fetched records. In WHERE clause, you can combine several conditions using AND or OR operators.
It is equivalent to the following function in QueryDSL:
It was a simple example. Let's show how to update several values at once.
Say, we want also to update the marital status. It is evident how to do this when it is defined as a String text, so now we will show how to update the value when it is defined as option of an option list. Assume the status in the model is defined as MaritalStatus option list with alternative options (SINGLE, MARRIED).
The queries will be: