Advertisement
Beginner SQL Server, In-Memory OLTP (Memory-Optimized Tables)

Does data stored in a memory optimized table get lost if the SQL Server instance restarts?

Short answer

By default, memory optimized tables are still durable, meaning their data is also persisted to disk and will be available again after a restart, though you can optionally configure a table as non durable for maximum performance in specific scenarios like caching, accepting that…

Save SQL Server mock interview
Advertisement
AModel answer
By default, memory optimized tables are still durable, meaning their data is also persisted to disk and will be available again after a restart, though you can optionally configure a table as non durable for maximum performance in specific scenarios like caching, accepting that its data will be lost on a restart.
CREATE TABLE CacheData (
  CacheKey NVARCHAR(100) PRIMARY KEY NONCLUSTERED,
  CacheValue NVARCHAR(MAX)
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_ONLY);
Real-world example
A caching layer for a busy web application uses a non durable memory optimized table with SCHEMA_ONLY durability, achieving maximum speed since the cached data can always be safely regenerated if the server restarts.
Likely follow-ups
  • What is the difference between SCHEMA_AND_DATA and SCHEMA_ONLY durability?
  • When is it appropriate to accept the risk of losing data on restart?
Related topics