sqlectron / sqlectron-core

Home Page:https://sqlectron.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deactivate foreign key constraints for SQLServer truncateAllTables

MasterOdin opened this issue · comments

truncateAllTables fails on newer versions of SQLServer (2017+ at least) if there's foreign keys that exist between rows. Similar to MySQL, the foreign key constraints must be disabled when deleting the tables. Unfortunately, SQLServer does not support disabling it at a DB level, rather it's per table, so have to do a sequence of:

  1. Turn off foreign key constraints for all tables
  2. Truncate all tables
  3. Re-index tables
  4. Turn on foreign key constraints for all tables