[id='sql-cache-store_{context}']
= SQL cache stores

SQL cache stores let you load {brandname} caches from existing database tables.
{brandname} offers two types of SQL cache store:

Table:: {brandname} loads entries from a single database table.
Query:: {brandname} uses SQL queries to load entries from single or multiple database tables, including from sub-columns within those tables, and perform insert, update, and delete operations.

[TIP]
====
Visit the code tutorials to try a SQL cache store in action.
See the link:{code_tutorials_root}/infinispan-remote/persistence[Persistence code tutorial with remote caches].
====

Both SQL table and query stores:

* Allow read and write operations to persistent storage.
* Can be read-only and act as a cache loader.
* Support keys and values that correspond to a single database column or a composite of multiple database columns.
+
For composite keys and values, you must provide {brandname} with Protobuf schema (`.proto` files) that describe the keys and values.
With {brandname} Server you can add schema through the {brandname} Console or Command Line Interface (CLI) with the [command]`schema` command.

[NOTE]
====
SQL cache stores do not support expiration when writes are allowed or segmentation.
====

Since a SQL cache store is designed to be used with an existing database table it would not contain expiration or segmentation metadata.
However, expiration can be used with a SQL Store when it is configured as read only.
When used as such, expiration acts as a way to remove stale values from memory, causing the cache to fetch the values from the database again to be cached.


[role="_additional-resources"]
.Additional resources
* link:{javadocroot}/org/infinispan/persistence/jdbc/common/DatabaseType.html[DatabaseType Enum lists supported database dialects]
* link:{configdocroot}infinispan-cachestore-sql-config-{schemaversion}.html[{brandname} SQL store configuration reference]
