반응형
  1. /**********************************************************************************************
    -- Title : [2k5] 인덱스된 열 이름 찾기
  2. -- Reference : dbrang.com
    -- Key word : 인덱스된 컬럼 이름 indexed column index_col
    **********************************************************************************************/
  3. use tempdb;

  4.  
  5. create table dbo.test
    ( a int not null, b int not null, c int not null
    , constraint pk_dbo_test primary key (a, b)
    );
  6. create schema ttt;
  7. create table ttt.test
    ( a int not null, b int not null, c int not null
    , constraint pk_ttt_test primary key (b, c)
    );
  8. -- 2k5 : INDEX_COL ( '[ database_name . [ schema_name ] .| schema_name ], table_or_view_name', index_id , key_id )
    -- 2k : INDEX_COL ( 'table' , index_id , key_id )
     
    select index_col('dbo.test', 1, 1) union all
    select index_col('dbo.test', 1, 2) union all
    select index_col('dbo.test', 1, 3) union all
    select index_col('ttt.test', 1, 1) union all
    select index_col('ttt.test', 1, 2) union all
    select index_col('ttt.test', 1, 3);
    /*
    a
    b
    NULL
    b
    c
    NULL
    */
  9. drop table dbo.test, ttt.test;
    drop schema ttt;
반응형

+ Recent posts