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.
Asked
Active
Viewed 2,374 times
-2
-
An id is just an id, the value should not matter! – jarlh Dec 17 '15 at 08:55
-
Read about triggers. – mic4ael Dec 17 '15 at 08:55
-
1instead of using delete statement use truncate and then perform insert. – Mukund Dec 17 '15 at 08:56
-
go into mysql table operation and set the auto increment value to 1 – rahul Dec 17 '15 at 08:59
-
1This question has been answered previously check this link. [Resetting the primary key to 1 after deleting all the data](http://stackoverflow.com/questions/6972275/resetting-the-primary-key-to-1-after-deleting-all-the-data) – srikanth r Dec 17 '15 at 08:59
-
@rahul, SQL Server is tagged, not MySQL. – jarlh Dec 17 '15 at 09:07
-
@jarlh oh my bad , i m sorry – rahul Dec 17 '15 at 09:20
-
The same query work in mysql – srikanth r Dec 17 '15 at 09:26
3 Answers
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