4

I have a problem creating an index with the advantage database server if it doesn't exist with a sql query.

My query looks like this:

 If not Exists(<SELECT Query for amount of indizes for one column>) then 
 Create Index Test on Tablename (No); endif

So I don't use FullTextSearchIndizes,because it is a integer field. Otherwhise it would look like this:

 If not Exists(SELECT * FROM tablename WHERE CONTAINS( * , 'Test' )) then 
 Create Index Test on Tablename (Name) Content; endif     

So, my only problem is how do I get the indices. I've read in other DBMS you can use sys.indexes and some other things.

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
André Dziurla
  • 187
  • 3
  • 9

2 Answers2

2

Take a look at the System tables:

https://devzone.advantagedatabase.com/dz/webhelp/Advantage10/devguide_system_tables.htm

In particular there is a table called system.indexes:

https://devzone.advantagedatabase.com/dz/webhelp/Advantage10/master_system_indexes.htm

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
0

Try something more like this, utilizing the system commands. This is a working example I use on an Advantage Database:

IF (SELECT Name FROM system.indexes
   WHERE Index_File_Name = 'GLDept.adi'
   AND Index_Expression = 'DeptNumber') IS NULL
THEN
   EXECUTE PROCEDURE sp_CreateIndex90( 
   'GLDept',
   'GLDept.adi',
   'DEPTNUMBER',
   'DeptNumber',
   '',
   2051,
   512,
   '' );
END IF;
Daniel
  • 515
  • 4
  • 13