Reseting all fields

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Reseting all fields

Post by InnerShadow »

I was wondering if there was a easier way to reset all of the values in a table back to 0 instead of a very long set of UPDATE statements?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Do the fields have default values? Delete the row and create a new one with the same primary key
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

jshpro2 wrote:Do the fields have default values? Delete the row and create a new one with the same primary key
Or use "REPLACE (primary_key) values ('1');" where primary_key is the name of the primary key column. This would set all the fields to the default rather than 0 though. Should be a little faster than a delete and an insert.
Post Reply