Copy Oracle Table Structure & Data
In Oracle database, there are two ways to replicate table structure and data.
- The CREATE TABLE AS SELECT statement can be used to copy the table structure and insert data into a new table. The syntax is as follows:
CREATE TABLE new_table AS SELECT * FROM original_table;
new_table is the name of the new table, while original_table is the name of the original table to be copied.
- Utilizing the INSERT INTO SELECT statement: this method allows you to duplicate table structure and insert data into an existing table. The syntax is as follows:
INSERT INTO new_table SELECT * FROM original_table;
Where new_table is the existing target table name, and original_table is the name of the original table to be copied.
It is important to note that the two methods mentioned above only copy table structure and data, but do not copy constraints, indexes, triggers, and other related objects. If you need to copy all related objects, you can use tools provided by Oracle such as Data Pump or third-party tools.