Solved

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

Posted on 2013-01-24
3
490 Views
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
0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
Comment Utility
Hi.

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,

Kevin
0
 

Author Comment

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

but not with php

mysql_query("truncate table $table");
0
 

Author Closing Comment

by:rgb192
Comment Utility
truncate works
 on php and mysql query editor
thanks
0

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 (http://dev.mysql.com/doc/refm…
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