Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2013-01-24
Medium Priority
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 60

Accepted Solution

Kevin Cross earned 2000 total points
ID: 38815146

TRUNCATE the table instead of dropping it.
REFMAN: http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

916 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