SQL Server 2016 – How to Migrate Tables with Foreign Keys to In-Memory OLTP

memory-optimized-tablessql-server-2016

SQL 2016 – I have 2 tables, Foo & Bar – Bar references Foo. I'd like to turn Foo into an in-memory optimized table, however as Bar references this, I can't do it.

I also can't make Bar in-memory due to its dependence on Foo.

Seems like I need to do this to both tables at the same time – is this possible without recreating both tables from scratch?

Best Answer

Seems like I need to do this to both tables at the same time

Correct. If you try to recreate the FK after migrating one table you will get:

Msg 10778, Level 16, State 0, Line 20
Foreign key relationships between memory optimized tables and non-memory optimized tables are not supported.

is this possible without recreating both tables from scratch?

Migrating to in-memory tables always requires recreating the tables from scratch. SSMS will rename your old tables, create the new in-memory tables, load them from your old tables, and drop your old tables.