오라클11g big_table 만들기

2010. 11. 16. 22:11오라클

big_table은 오라클을 베이스로 테스트를 해본 사람이라면
누구나가 알고 있는 테이블이다.
다음은 big_table은 만드는 SQL이다.
11g 에서는 10g의 all_objects 테이블보다 2개의 컬럼(NAMESPACE, EDITION_NAME)
늘었다.

/* 테이블 껍데기 만들기 */
create table big_table
as
select rownum id, a.*
 from all_objects a
where 1=0;
/* nologging 모드로 만들기 */
alter table big_table nologging;

/* 100만개 로우를 가진 테이블 만들기 */
declare
 l_cnt number;
 l_rows number := 1000000;
begin
 insert /*+ append */
 into big_table
 select rownum, a.*
  from all_objects a;
 
 l_cnt := sql%rowcount;
 
 commit;
 
 while (l_cnt < l_rows)
 loop
  insert /*+ APPEND */ into big_table
  select rownum+l_cnt,
   OWNER, OBJECT_NAME, SUBOBJECT_NAME,
   OBJECT_ID,DATA_OBJECT_ID,
   OBJECT_TYPE, CREATED, LAST_DDL_TIME,
   TIMESTAMP, STATUS, TEMPORARY,
   GENERATED, SECONDARY, NAMESPACE, EDITION_NAME
  from big_table
 where rownum <= l_rows-l_cnt;
 l_cnt := l_cnt + sql%rowcount;
 commit;
    end loop;
end;
/

/* 기본키 만들기 */
alter table big_table add constraint
big_table_pk primary key(id);

/* 통계정보 수집하기 */
begin
 dbms_stats.gather_table_stats
  ( ownname  => user,
    tabname  => 'BIG_TABLE',
    method_opt => 'for all indexed columns',
    cascade    => TRUE );
 end;
 /

 select count(*) from big_table;