0

I have created a memory optimized table type in my database like so:

create type tblLocation_InMem as table(
     IndexLocation int not null index IX_LocInMem,
     IndexRootLocation int not null,
     fldLocCrumbs nvarchar(1024) not null
)
with (memory_optimized=on)

This table type is to be used in a big query that needs to access the data stored in it over multiple select statements like so:

declare @myLocTbl as tblLocation_InMem;
insert into @myLocTbl <some select statement>;
select <stuff> from <some table> join @myLocTbl on <join stuff>;
select <other stuff> from <other table> join @myLocTbl on <more join stuff>;

Everything works fine, but I looked into my SQL data folder for the database's File_MemOpt file group and I see stuff like this for my In-Memory table type under the $HKv2 folder:

enter image description here

Apparently my in memory table type isn't quite in-memory. Is there a way I can use this table type and keep it strictly in memory without all this disk writing. I thought by creating just an in-memory table type I was avoiding any disk activity. I also tried creating an in-memory table definition and specifying durability=schema_only, but this still created stuff on the disk. Should I just use table variables?

I'm not worried about persistence over a restart or anything like that. The select request happens in the context of a REST web request. If the server restarts during the request, then the request will just have to start all over.

Ian
  • 4,169
  • 3
  • 37
  • 62

1 Answers1

0

Memory-optimized tables are still persisted in disk. If you really want a memory-only table without data persistence, create it with

(with memory_optimized=on, durability=schema_only)

Read the documentation for further details:

https://learn.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/introduction-to-memory-optimized-tables

https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql

FBergo
  • 1,010
  • 8
  • 11
  • Those documents are about in-memory tables. I'm reading about an in-memory table type (https://msdn.microsoft.com/en-us/library/dn535766(v=sql.120).aspx), which I thought would do what I wanted, but apparently not. When I try to actually create in-memory tables with durability=schema_only I get an error when trying to run my SQL statement that says: "A user transaction that accesses memory optimized tables or natively compiled modules cannot access more than one user database or databases model and msdb, and it cannot write to master" – Ian Mar 26 '18 at 22:29