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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 60

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using cfstoredproc to return query data 2 69
MySQL limit and not so limited 13 61
MySQL Persistent Connections 10 55
WordPress  Failed to Import Media 8 65
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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