So there I was, working on another task to create a data subset. This time, keep data for the current year only.
Here’s a similar post, How to rebuild table when you don’t have TOAD
My code has something like: create table tn_backup as select * from tn;
In a code review, a colleague suggested to rename the table since it would be faster.
Renaming the table is fast, but what about all the constraints and indexes on the table? They all will have to be renamed since duplicates are not allowed.
Since the table was relatively simple and did not have any Foreign Key, I thought I would entertain the idea.
Here is the test case Renaming tables test case
The table used in the test case has Foreign Key to it, but just imagine it didn’t.
Another options is to rename the table and drop all the constraints and indexes.
Rename table. Drop all constraints and indexes on the renamed table. Create new table.
Create backup using CTAS, Drop table. Create new table.
Which one would you chose?