delete table and have auto increment primary key start back at 1

Posted on 2013-01-24
Last Modified: 2013-01-24
mysql_query("drop table $table;");
mysql_query("create table $table like $oldtable;");

these php commands are not running
but these commands run in the mysql query editor

I want to do
delete from table
but I have an auto increment primary key

I want to delete table and have auto increment primary key start back at 1
Question by:rgb192
  • 2
LVL 59

Accepted Solution

Kevin Cross earned 500 total points
Comment Utility

TRUNCATE the table instead of dropping it.

Best regards and happy coding,


Author Comment

Comment Utility
truncate table tablename worked in a mysql workbench query editor

but not with php

mysql_query("truncate table $table");

Author Closing Comment

Comment Utility
truncate works
 on php and mysql query editor

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now