1

The command EXEC sp_msforeachtable 'TRUNCATE TABLE ?' returns the following error:

The EXEC SQL construct or statement is not supported.

enter image description here

I execute the query like this:

enter image description here

Question

How do I erase all data, but keep existing tables, relationships, keys, and indexes settings?

makerofthings7
  • 60,103
  • 53
  • 215
  • 448

1 Answers1

0

Turn off all constraints, delete all records, turn constraints back on:

EXEC sp_MSForEachTable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’
GO
EXEC sp_MSForEachTable ‘DELETE FROM ?’
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL';
GO
Justin
  • 2,093
  • 1
  • 16
  • 13