Quantcast
Viewing all articles
Browse latest Browse all 667

Renaming Table, Constraints, Indexes

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.

Option 1:
Rename table. Drop all constraints and indexes on the renamed table. Create new table.

Option 2:
Create backup using CTAS, Drop table. Create new table.

Which one would you chose?


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 667

Trending Articles