1.构造一个包含114688行记录的实验用大表test_tab1
sec@ora10g> conn sec/sec
Connected.
sec@ora10g> create table test_tab1 as select * from emp;
Table created.
sec@ora10g> insert into test_tab1 select * from test_tab1;
14 rows created.
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
sec@ora10g> /
57344 rows created.
sec@ora10g> commit;
Commit complete.
sec@ora10g> select count(*) from test_tab1;
COUNT(*)
----------
114688
2.查询测试表的空间分配情况
sec@ora10g> select extent_id,file_id,block_id,blocks from dba_extents where segment_name='TEST_TAB1' and wner='SEC';
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
0 5 177 8
1 5 185 8
2 5 193 8
3 5 201 8
4 5 209 8
5 5 217 8
6 5 225 8
7 5 233 8
8 5 241 8
9 5 249 8
10 5 257 8
11 5 265 8
12 5 273 8
13 5 281 8
14 5 289 8
15 5 297 8
16 5 393 128
17 5 521 128
18 5 649 128
19 5 777 128
20 5 905 128
21 rows selected.
3.删除hiredate列,move表,验证空间使用情况--结果:空间得到释放
sec@ora10g> alter table test_tab1 drop column hiredate;
Table altered.
sec@ora10g> alter table test_tab1 move tablespace sec_d;
Table altered.
sec@ora10g> select extent_id,file_id,block_id,blocks from dba_extents where segment_name='TEST_TAB1' and wner='SEC';
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
0 5 305 8
1 5 313 8
2 5 321 8
3 5 329 8
4 5 337 8
5 5 345 8
6 5 353 8
7 5 361 8
8 5 369 8
9 5 377 8
10 5 385 8
11 5 1033 8
12 5 1041 8
13 5 1049 8
14 5 1057 8
15 5 1065 8
16 5 1161 128
17 5 1289 128
18 5 1417 128
19 5 1545 128
20 rows selected.
4.禁用多列,move表,验证空间使用情况--结果:空间得到释放
alter table test_tab1 set unused column comm;
alter table test_tab1 set unused column sal;
alter table test_tab1 set unused column mgr;
sec@ora10g> alter table test_tab1 move tablespace sec_d;
Table altered.
sec@ora10g> select extent_id,file_id,block_id,blocks from dba_extents where segment_name='TEST_TAB1' and wner='SEC';
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
0 5 177 8
1 5 185 8
2 5 193 8
3 5 201 8
4 5 209 8
5 5 217 8
6 5 225 8
7 5 233 8
8 5 241 8
9 5 249 8
10 5 257 8
11 5 265 8
12 5 273 8
13 5 281 8
14 5 289 8
15 5 297 8
16 5 393 128
17 5 521 128
18 5 649 128
19 rows selected.
5.将所置unused列drop掉,move表,验证空间使用情况--结果:空间使用情况更没有变化
sec@ora10g> alter table test_tab1 drop unused columns;
Table altered.
sec@ora10g> alter table test_tab1 move tablespace sec_d;
Table altered.
sec@ora10g> select extent_id,file_id,block_id,blocks from dba_extents where segment_name='TEST_TAB1' and wner='SEC';
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
0 5 305 8
1 5 313 8
2 5 321 8
3 5 329 8
4 5 337 8
5 5 345 8
6 5 353 8
7 5 361 8
8 5 369 8
9 5 377 8
10 5 385 8
11 5 777 8
12 5 785 8
13 5 793 8
14 5 801 8
15 5 809 8
16 5 905 128
17 5 1033 128
18 5 1161 128
19 rows selected.
6.小结
这个实验列出了两种drop列的方法,以及在move表后表的存储空间的变化情况。
-- The End --
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70034820/viewspace-2993720/
,如需转载,请注明出处,否则将追究法律责任。