Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a row in a table of defaults to another row

Status
Not open for further replies.

TomHW

Programmer
Sep 8, 2004
100
US
I have a table that is used to store default values. It has two rows, one which has the default values and one which has the generic, original defaults. It is set up like so:

tblDefaults
-----------
ID
field1
field2
...
fieldN

The current defaults row has an ID of 1 while the generic defaults row has an ID of 0. I need to be able to reset the current row to the generic row without removing the generic row. Is there a way to do this without losing the generic row, without creating a new table, and without having to explicitly set each individual field?

Thanks for any help,
Tom
 
My solution, although ugly, was to set the default value of ID to 1. Then I could DELETE the row with ID = 1 and run the statement:

INSERT INTO tblDefaults (field1, field2, ...)
SELECT field1, field2, ...
FROM tblDefaults
WHERE ID = 0;

This in effect creates a new row and ID is automatically filled in with a value of 1. If the DELETE fails or some code attempts to add another row without setting the ID an error will occur since there will already be an ID = 1, but it works none the less.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top