# Truncate table to reset id back to 1

**URL:** <https://www.ruby-forum.com/t/truncate-table-to-reset-id-back-to-1/109716>\
**Category:** Rails\
**Created:** [July 18, 2007, 10:05am UTC](https://www.ruby-forum.com/t/truncate-table-to-reset-id-back-to-1/109716 "2007-07-18T10:05:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobobyhere](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5e925/32.png) [@nobobyhere](https://www.ruby-forum.com/u/nobobyhere)\
**Post date:** [July 18, 2007, 10:05am UTC](https://www.ruby-forum.com/t/truncate-table-to-reset-id-back-to-1/109716/1 "2007-07-18T10:05:22Z")

</div>

What im using now is ActiveRecord::Base.connection.execute(‘TRUNCATE  
table\_products’) to reset the id back to 1. Is there another way without  
using direct sql command to reset the id back to 1?

---

<div class="post-metadata">

**Author:** ![nobobyhere](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5e925/32.png) [@nobobyhere](https://www.ruby-forum.com/u/nobobyhere)\
**Post date:** [July 18, 2007, 12:33pm UTC](https://www.ruby-forum.com/t/truncate-table-to-reset-id-back-to-1/109716/2 "2007-07-18T12:33:22Z")

</div>

in mysql:

ALTER TABLE

 SET AUTO\_INCREMENT = 1
