删除和截断和表大小

问题描述 投票:0回答:1

我尝试在下面的查询中了解删除和截断后对表大小的影响。

select * from SALES_HISTORY;
Output:
Product     Month       Sales
sony    22-DEC-17   24000
sony    22-DEC-17   24000
sony    22-DEC-17   24000
sony    22-DEC-17   24000
sony    22-DEC-17   24000
sony    22-DEC-17   24000

Delete from sales_history:
commit;

select segment_name,segment_type,bytes/1024/1024 MB
from dba_segments
where segment_type='TABLE' and segment_name='SALES_HISTORY';

Output:
segment_name    segment_type   MB
SALES_HISTORY   TABLE         0.0625

Truncate table SALES_HISTORY;

此后,我再次尝试查找表的大小,但似乎与下面相同,如果截断了所有行,它应该不为零

Output:
segment_name    segment_type   MB
SALES_HISTORY   TABLE         0.0625

我需要了解删除和截断后对表和水印大小的影响。

sql oracle sql-delete truncate
1个回答
0
投票

[如果您使用11g R2或更高版本,请查看DROP ALL STORAGE是否满足您的要求。看下面的例子:

SQL> create table test_truncate as select level id, sysdate + level datum
  2  from dual connect by level <= 100000;

Table created.

SQL> select segment_name,segment_type,bytes/1024/1024 MB
  2  from dba_segments
  3  where segment_type='TABLE' and segment_name='TEST_TRUNCATE';

SEGMENT_NAME         SEGMENT_TYPE               MB
-------------------- ------------------ ----------
TEST_TRUNCATE        TABLE                       3

SQL> truncate table test_truncate;

Table truncated.

SQL> select segment_name,segment_type,bytes/1024/1024 MB
  2  from dba_segments
  3  where segment_type='TABLE' and segment_name='TEST_TRUNCATE';

SEGMENT_NAME         SEGMENT_TYPE               MB
-------------------- ------------------ ----------
TEST_TRUNCATE        TABLE                   ,0625

SQL> truncate table test_truncate DROP ALL STORAGE;

Table truncated.

SQL> select segment_name,segment_type,bytes/1024/1024 MB
  2  from dba_segments
  3  where segment_type='TABLE' and segment_name='TEST_TRUNCATE';

no rows selected

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.