Swiftybase
Function StackDatabaseMysqlExamples

Update Query

Example 1: Update Data

In this example, we'll use the MySQL Execute function with the Type set to Update to modify data and return the number of affected rows.

Add MySQL Execute Function

Start by adding the MySQL Execute function. Give it a Result Name and set the Type to Update.

Write the SQL Query

In the function configuration, write the SQL query you want to use to update the data.

Assume we have a users table and want to update the name of a user by their id. The users table schema looks like this:

CREATE TABLE `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `email` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `age` int unsigned NOT NULL,
  `activated` tinyint(1) NOT NULL DEFAULT '1',
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Now write the following update query:

UPDATE users SET name = ? WHERE id = ?

Fill the Arguments

Provide the values for the update. Make sure the list literal is enabled:

["$upperName", 7]

Testing

When you run the query, it will update the user's name and return the number of affected rows.

On this page