How to insert all rows from one table to another?
Knowledgebase article on how to insert all rows from one table to another.
Introduction
Sometimes you need to reingest all the data from one table to another.
For example, you might want to reingest data from a staging table to a production table. This article shows how to do this using the INSERT INTO
statement.
Example
Below is a simple example on how it works and how to test:
- Create a sample database
- Create a sample table
- Insert some data into the source table
- Check the number of rows in the source table
- Create a new table with the same structure as the source table.
- Insert all rows from the source table to the target table.
- Check the number of rows in the target table
If you want to modify the structure of the new table, you can first display the structure of the source table.
Then create the new table with the modified structure. In our case we want to add a new column population
to the target table.
- Insert all rows from the source table to the target table, including the new column. The population field is set to 0 for all rows.
- Check the data in the target table
· 2 min read