Background Image
조회 수 15143 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

CUBRID에서 지원하는 언로드 유틸을 통하여 인덱스생성 구문을 만들 수 있다.
그러나 unique index, primary key, foreign key 를 만들기 위해서는 별도의 수작업이 필요하므로
아래 질의와 같이 시스템 카다로그인 db_index, db_index_key 시스템테이블을 이용한 생성구문을 만들 수 있다.

select 'CREATE' || decode(ax.is_reverse, 'YES', ' REVERSE', '')
                || decode(ax.is_unique, 'YES', ' UNIQUE', '')
                || ' INDEX ' || ax.index_name || ' ON ' || ax.class_name || bx.key_attr || ' ;' as create_index_value
from   db_index ax,
       (
            select class_name,  index_name,
                   '(' || max(S.a)
                       || decode( max(S.b),'','',',' || max(S.b))
                       || decode( max(S.c),'','',',' || max(S.c))
                       || decode( max(S.d),'','',',' || max(S.d))
                       || decode( max(S.e),'','',',' || max(S.e))
                       || decode( max(S.f),'','',',' || max(S.f))
                       || decode( max(S.g),'','',',' || max(S.g))
                       || decode( max(S.h),'','',',' || max(S.h))
                       || decode( max(S.i),'','',',' || max(S.i))
                       || decode( max(S.j),'','',',' || max(S.j))
                       || decode( max(S.k),'','',',' || max(S.k))
                       || decode( max(S.l),'','',',' || max(S.l))
                       || ')' as key_attr
            from  (
                    select A.class_name  as class_name, A.index_name  as index_name,
                        decode(B.key_order,0,  B.key_attr_name,'') as a,
                        decode(B.key_order,1,  B.key_attr_name,'') as b,
                        decode(B.key_order,2,  B.key_attr_name,'') as c,
                        decode(B.key_order,3,  B.key_attr_name,'') as d,
                        decode(B.key_order,4,  B.key_attr_name,'') as e,
                        decode(B.key_order,5,  B.key_attr_name,'') as f,
                        decode(B.key_order,6,  B.key_attr_name,'') as g,
                        decode(B.key_order,7,  B.key_attr_name,'') as h,
                        decode(B.key_order,8,  B.key_attr_name,'') as i,
                        decode(B.key_order,9,  B.key_attr_name,'') as j,
                        decode(B.key_order,10, B.key_attr_name,'') as k,
                        decode(B.key_order,11, B.key_attr_name,'') as l
                    from db_index     A,
                         db_index_key B
                    where A.class_name = B.class_name
                      and A.index_name = B.index_name
                    order by A.class_name, A.index_name, B.key_order
            ) as S
        group by class_name, index_name
       ) bx
where  ax.class_name in ( select C.class_name
                         from db_class C
                         where C.class_type = 'CLASS'
                           and C.owner_name <> 'DBA'  -- 특정 계정이 소요한 테이블을 제외할 수 있다.
                         )
  and    ax.class_name = bx.class_name
  and    ax.index_name = bx.index_name
order by bx.class_name, bx.index_name     ;

만약 index가 아닌 PK, FK일 경우 조건 중 ax.is_primary_key, ax.is_foreign_key 컬럼의 값(YES, NO)를 이용하여 PK, FK 생성 구문을 만들 수 있다.
PK를 생성구문을 만들고 싶을 경우  "ALTER TABLE  ax.class_name ADD PRIMARY KEY(bx.key_attr);" 문과 같이 생성할 수 있도록 수정해 주면 된다.


  1. 오라클의 order by 시 first와 last 대체 사용법

    Date2011.12.22 Category질의작성 By이용미 Views20179
    Read More
  2. 데이터 존재하면 update, 존재하지 않으면 insert 방법(ON DUPLICATE KEY UPDATE)

    Date2010.08.11 Category질의작성 By손승일 Views38002
    Read More
  3. function based index 대체 방법

    Date2010.07.01 Category질의작성 By남재우 Views13420
    Read More
  4. 모든 필드에 하나 이상 중복 값 찾기

    Date2010.04.27 Category질의작성 By정만영 Views21591
    Read More
  5. group by 사용 방법 및 여러 필드중 하나의 필드에 대하여만 group by 처리 방법

    Date2010.02.26 Category질의작성 By남재우 Views21713
    Read More
  6. CUBRID에서 대소문자 관리

    Date2010.01.30 Category질의작성 By남재우 Views19510
    Read More
  7. 문자 코드셋(UTF-8, EUC-KR) 사용시 CUBRID 는?

    Date2010.01.01 Category질의작성 By남재우 Views22398
    Read More
  8. Integer 컬럼의 결과에 + or – 연산을 할 때 주의해야 할 점

    Date2009.12.31 Category질의작성 By웁쓰 Views13493
    Read More
  9. CUBRID설치 후 default설정 상태에서 Query Plan보기(CSQL모드)

    Date2009.12.31 Category질의작성 Bycubebridge Views16507
    Read More
  10. 쿼리로 인덱스 정보 확인하기

    Date2009.12.29 Category질의작성 By시난 Views24644
    Read More
  11. 쿼리로 테이블이 존재하는지 확인하기

    Date2009.12.28 Category질의작성 By시난 Views23521
    Read More
  12. CUBRID 예약어 사용방법

    Date2009.12.09 Category질의작성 By정만영 Views17183
    Read More
  13. 시스템 테이블을 이용한 인덱스 생성 구문 만들기

    Date2009.12.02 Category질의작성 Byjanus Views15143
    Read More
  14. 예제를 이용한 중복데이터 삭제

    Date2009.12.02 Category질의작성 Byjanus Views18541
    Read More
  15. CUBRID에서 응용프로그램 쿼리 binding 구문이 있을 경우 plan의 차이

    Date2009.11.06 Category질의작성 Bycubebridge Views15701
    Read More
  16. CUBRID DB 내의 auto_increment 값을 초기화 하자.

    Date2009.10.28 Category질의작성 By손승일 Views29734
    Read More
  17. 임의의 컬럼을 rownum 으로 업데이트 하기

    Date2009.07.01 Category질의작성 ByPrototype Views22536
    Read More
  18. 중복데이터 제거 방법

    Date2009.07.01 Category질의작성 ByPrototype Views25068
    Read More
  19. CUBRID 2008에서의 class 정보를 확인하는 sql 쿼리문.

    Date2009.06.30 Category질의작성 Byseongjoon Views13288
    Read More
  20. pivot() 간략하게 구현하기

    Date2009.06.24 Category질의작성 By남재우 Views23429
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales