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
ID: 38815146

TRUNCATE the table instead of dropping it.

Best regards and happy coding,


Author Comment

ID: 38816659
truncate table tablename worked in a mysql workbench query editor

but not with php

mysql_query("truncate table $table");

Author Closing Comment

ID: 38816672
truncate works
 on php and mysql query editor

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL Error 3 43
get the data all row not only one row php 4 62
updating the date data 12 30
Mysql Left Join Case 10 55
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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