Click to See Complete Forum and Search --> : Database updates


Spectre5000
September 20th, 2001, 11:24 AM
There isn't a forum out here specific for SQL, and seeing as I am writing this in VB I figured I would post
this question out here. The question:

Is there a way to move data between 2 tables in a database? I know I could just query the information in one
table, and then use the update statement to update the new table, and then delete the old information from
the first table. But I want to know if there is a way to move information from table 1 to table 2. Example:

Table 1 is a ticketheader table, containing various information about open tickets. Table 2 is the ticketheaderhistory
table, which contains the same information as table 1, only the information in table 2 is all of the closed
tickets. I want to take some information in table 1 and put it into table 2 when the ticket is closed/cashed out,
without having to do a query, an update, and then a delete. Can this be done in one step? Can the information
be moved from table 1 to table 2 in one step, thereby eliminating the need for query/update/delete method?

Cakkie
September 20th, 2001, 04:16 PM
You cannot do this in one time, but you can do it in 2. You can use the SELECT INTO or the INSERT INTO ... SELECT FROM statements. These allow you to insert data from one table directly into another. Then all you need to do is to delete it from the first table.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook