# TransactionSetSavepoint

Sets a savepoint in the current transaction.

This savepoint can then be a rollback point when executing a rollback via `transactionRollback( "mySavepointName" )`.

## Method Signature

```
TransactionSetSavepoint(savepoint=[string])
```

### Arguments

| Argument    | Type     | Required | Description               | Default |
| ----------- | -------- | -------- | ------------------------- | ------- |
| `savepoint` | `string` | `true`   | Specify a savepoint name. |         |

## Examples

#### Using TransactionSetSavepoint with TransactionRollback

Here's a simple example of using multiple savepoints within a transaction:

```java
transaction {
    queryExecute( "INSERT INTO vehicles (id,make) VALUES (8, 'Ford' )", {}, { datasource : "carDB" } );
    transactionSetSavepoint( 'insert' );

    queryExecute( "UPDATE developers SET name = 'Chevrolet' WHERE id=8", {}, { datasource : "carDB" } );
    transactionSetSavepoint( 'update' );

    // more stuff ...
    transactionRollback( 'insert' );
}
```

In this example, the UPDATE will be rolled back while the INSERT statement will remain. Remember that in `transactionRollback()`, the savepoint is not the name of a single savepoint to roll back, but the name of the savepoint to rollback TO.

### Roll back to a specified savepoint

This example runs multiple queries with a savepoint for each, and rolls back to the 'useradded' savepoint if the last query fails.

[Run Example](https://try.boxlang.io/?code=eJxNjDEOgzAMRef4FBZTmNjbW5QTmMQSUZHTBoOIUO5O3YnlL%2B%2F9Nx0PLSQrBU1Z8AQ3DJhk5aK4%2FRbcDY%2BsI%2B38yUnUY2ecYuTYYf80sdq%2F%2FRMkWWcu%2BN24VHAYSMOMnqQi96bdu6%2B8LBOFt7dMgwYX92Ew1w%3D%3D)

```java
bx:transaction {
	// insert user
	transactionSetSavepoint( "useradded" );
	try {
	}
	// another query
	 catch (any e) {
		transactionRollback();
	}
}

```

## Related

* [IsInTransaction](/boxlang-language/reference/built-in-functions/jdbc/isintransaction.md)
* [IsWithinTransaction](/boxlang-language/reference/built-in-functions/jdbc/iswithintransaction.md)
* [PreserveSingleQuotes](/boxlang-language/reference/built-in-functions/jdbc/preservesinglequotes.md)
* [QueryExecute](/boxlang-language/reference/built-in-functions/jdbc/queryexecute.md)
* [TransactionCommit](/boxlang-language/reference/built-in-functions/jdbc/transactioncommit.md)
* [TransactionRollback](/boxlang-language/reference/built-in-functions/jdbc/transactionrollback.md)


---

# 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://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/jdbc/transactionsetsavepoint.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.
