2

I have a table and it's first column sl is auto incrementing. After populating my table, I removed first two rows, and the first entry is having sl 1. Is it possible to reset it to 1 maintaining AI? I am using PHP MyAdmin.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Alfred
  • 21,058
  • 61
  • 167
  • 249

4 Answers4

3
ALTER TABLE tablename AUTO_INCREMENT = 1;
John Conde
  • 217,595
  • 99
  • 455
  • 496
1

I'm not sure if i got your question but if you want your column sl to be renumbered do ALTER TABLE your_table DROP sl and then ALTER TABLE your_table ADD sl your_definitions

EKrueger
  • 730
  • 8
  • 20
1

If you just want to reset the auto-number back to 1 you can use either:

DBCC CHECKIDENT (tablename, RESEED, 0)

or

TRUNCATE TABLE tablename

The first option will simply reset your auto-number counter while the second will clear your table of all data and reset the counter.

Is this what you were asking?

Naveed S
  • 5,106
  • 4
  • 34
  • 52
garyg
  • 11
  • 1
0

Try using ALTER TABLE tableName AUTO_INCREMENT=0;. The next record will be entered with index 1.

Yash Kumar Verma
  • 9,427
  • 2
  • 17
  • 28