TechTalk: Creating an Index with ODBC

DB2
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Q: I know I need a unique index to update files with ODBC, but how do I create that index?

A: You can create the index as a logical file over the physical file using DDS, but a quicker way is to use SQL. You can use SQL either from OS/400 (STRSQL or a Query Management Query) or from your ODBC client program. From a place where you can enter SQL commands?RUMBA for Database Access, for example?type the following code.

 CREATE UNIQUE INDEX idxlib/idxnam ON fillib/filnam (fldnam ASC) 

In this statement, substitute the library you want the index to go to for "idxlib" and the name of the index you want to create for "idxnam." Also, substitute the library and file names of the file you want to update for "fillib" and "filnam," respectively. "Fldnam" represents the field that you want to use to create the index, and "ASC" stands for ascending sort (you can put "DSC" for descending sort).

You can specify more than one field to create the index. Just be sure the combination of fields is unique for each record. Once the index is created, the index will automatically be picked up the next time you connect to your data source, and you can then update your data.

? Brian Singleton

BLOG COMMENTS POWERED BY DISQUS