14

SQL CE does not support TRUNCATE command. To clear a table I have to use DELETE. Is there a quicker/better way to clear the data then the following command?

DELETE FROM FooTable WHERE id !='ABC'
Damascus
  • 6,553
  • 5
  • 39
  • 53
KMC
  • 19,548
  • 58
  • 164
  • 253

2 Answers2

36

You don't have any better way to do that, DELETE is the SQL Command for SQL CE to DELETE ROWS, anyway TRUNCATE TABLE deletes every row in a table, so your DELETE query must be executed also at SQL Server if you want to DELETE all the rows with id different from 'ABC'.

In the case you want to DELETE all the rows in SQL CE you must use

DELETE FROM FooTable

See you, I hope this post was useful to you.

Amedio
  • 895
  • 6
  • 13
  • if you want to delete as well as reseed a table add another statement to reassign the ID column as in this link http://stackoverflow.com/questions/15271143/reseed-identity-column-in-sql-compact – Michael Bahig Dec 12 '15 at 22:22
3

No, other than DROP TABLE, CREATE TABLE and INSERT the surviving data (if there are any)

ErikEJ
  • 40,951
  • 5
  • 75
  • 115