-2

When I delete all of old data. After that I want insert new data that the first new data I insert start with no.1 . How I can do that.

Taryn
  • 242,637
  • 56
  • 362
  • 405

3 Answers3

1

Use TRUNCATE TABLE tblName to remove all the data in a table. Then insert your new data.

sicKo
  • 1,241
  • 1
  • 12
  • 35
0

If you insist on using DELETE FROM instead of TRUNCATE for some reason, you can reseed the Identity afterwards. The following Statement will lead to the next inserted line to get the identity-value 1. DBCC CHECKIDENT ('[dbo].[Table_1]', reseed, 0)

TRRR
  • 36
  • 3
0

Instead of delete use Truncate table <tablename>.

This will reset your clustered index and new entry will start with 1 or whatever you define.

http://www.orafaq.com/faq/difference_between_truncate_delete_and_drop_commands

http://beginner-sql-tutorial.com/sql-delete-statement.htm

What's the difference between TRUNCATE and DELETE in SQL

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58