Oracle Create Table as Select * from Another_Table same table space

时间:2016-07-11 19:03:50

标签: oracle

I didn't design the DB so don't judge me on this.

I have a log table that is receiving A LOT of entries. I only need to keep a day or so on this this log table. My initial thought was:

In a single transaction: 1. rename the log table 2. create the original log table from the renamed log table 3. commit the trx and life goes on

The second time this happens I drop the renamed table and do it all over again. This will run as an Oracle job once a day.

The original question: Would anyone know if I specify a table space name in table #1 like so:

create table "my_user"."first_table" (pkid number, full_name varchar2(50)) nologging tablespace "my_custom_tablespace";

Then I do something like:

create table second_table as select * from first_table where 1=2  -- because I only want the structure

Will my second_table be in the same table_space?

Thanks in advance for your help.

1 个答案:

答案 0 :(得分:0)

如果您使用的是带有分区的Enterprise Edition,那么更简单的解决方案是使用间隔分区表,每天使用一个分区。然后在不需要时截断分区。

如果没有,则使用两个表,一个同义词指向正在插入的'当前',以及一个从两个表的并集中选择的视图。每晚工作会截断“旧”表并切换同义词以使其成为“新”表。