Thursday, July 5, 2007

Copy rows from one table to another

Sometimes you wish to copy contents from one table - for instance a backup table - to another table. That can be done using "insert into ... select", here is a simple example:


INSERT INTO table_target (col1, col2)
select col1, col2 from table_source
where new = 1
It will copy the rows from table_source where the col "new" contains 1 as news rows into table_target! Simple backup procedure :-)

No comments: