Article ID: 195534
Article Last Modified on 7/1/2004
Column name Description. INDEX_NAME Name of the index. INDEX_DESCRIPTION Description of the index. INDEX_KEYS Column(s) that comprise the index expression.
* Substitute the server name.
#DEFINE Connect_String 'DRIVER={SQL Server};SERVER=MY_SERVER;' + ;
'DATABASE=PUBS;UID=UserName;PWD=StrongPassword'
* Create a cursor to contain the information to return.
CREATE CURSOR SYS_Indexes (Table_Name c(128), Index_Name c(128), ;
Index_Description c(128), Index_Keys c(128))
* Connect to SQL Server.
gnConnHandle=SQLSTRINGCONN(Connect_String)
IF gnConnHandle>0
* Get the tables available on SQL Server.
SQLConnTables=SQLTABLES(gnConnHandle)
IF SQLConnTables>0
SELECT SQLResult
INCnt=0
DO WHILE !EOF()
* Create a command to execute the stored procedure.
SQLCommand="sp_helpindex " + ALLTRIM(Table_Name)
* Execute the stored procedure and return data to a cursor.
=SQLEXEC(gnConnHandle,SQLCommand,'tmp_sys_data')
* Select the cursor.
SELECT tmp_sys_data
INSERT INTO SYS_Indexes ;
VALUES ;
(SQLResult.table_name, tmp_sys_data.Index_Name, ;
tmp_sys_data.Index_Description, ;
tmp_sys_data.Index_Keys)
SELECT SQLResult
SKIP
ENDDO
=SQLDISCONN(gnConnHandle)
ENDIF
ENDIF
SELECT SYS_Indexes
BROW LAST
CLOSE ALL
RETURN
Keywords: kbhowto kbsqlprog kbdatabase kbsample kbclientserver KB195534