Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reset an autoinc field to 0?

Status
Not open for further replies.

ulises48

Technical User
Feb 3, 2012
17
MX
Hello all. I have a table with an autoinc integer field. I am obviously doing some testing.
When I DELETE ALL -> PACK I thought that the field resets to 0 but that's not happening. Only way I have found to reset the field to 0 is deleting the field from the database and creating it again, but I don't think this is the best way to do it... so:
How do you reset an autoinc field to 0 with a command?
Thank you in advance.
Ulises
 
Hi Ulises.

Use ALTER TABLE Whatever ALTER COLUMN Whatever I AUTOINC NEXTVALUE 0.

Doug
 
Ulises,

Doug has given you the answer. However, you should be cautious about resetting the field in this way.

If the field in question is a primary key (chances are that it is), and if you've got other tables that have foreign keys pointing to it, then resetting the primary key to 0 will kill referential integrity within the database.

That might not be a problem in your case, but it's something you need to be aware of.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top