Db2で索引を作る
テーブル名と列名を指定。
$ db2 "create index test_index on sales(SALES)" DB20000I The SQL command completed successfully.
作った索引はテーブル名を指定することで見れる。
$ db2 " SELECT TABNAME, INDNAME, COLNAMES FROM SYSCAT.INDEXES WHERE TABNAME = 'SALES'" TABNAME INDNAME COLNAMES -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SALES TEST_INDEX +SALES 1 record(s) selected.
ちなみに索引を作る際はクオテーションがないと以下のエラーになる。ご注意を。
$ db2 create index test_index on sales(SALES) bash: syntax error near unexpected token `('