How do I remove an index from a table

tharzarob
Kilo Explorer

How do I remove an index from a table?   I created an index using a field that I thought originally should be unique but it turns out that field is not a determining characteristic of the record.   Is there a way to remove this index?

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Robert,



Reach out to customer support. They can assist with this as it requires low level interaction with the database.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Robert,



index can only be removed by ServiceNow support personnel, customers cannot do this operation. Please raise a HI ticket for the same.


HI Service Portal - ServiceNow


Contact Support | ServiceNow


Dan_Berglin
Giga Expert

You can drop indexes, but I don't think it's supported and I don't recommend doing it.



Use at your own risk in sandbox-environments:


//dropIndex("task", "sys_updated_on_2");




function dropIndex(tableName, indexName) {




      var td = new GlideTableDescriptor(tableName);


              td.getSchema();




      var indexes = td.getIndexDescriptors();




      for (var iter = indexes.values().iterator(); iter.hasNext();) {


              var idx = iter.next();




              if (idx.isPrimary())


                      continue;




              var flds = idx.getFields();


              var idxname = idx.getName();


              var parts = idxname.split("_");


              var unique = idx.isUnique();




              if (idxname === indexName) {


                      gs.print("Index " + indexName + " found and will be dropped");


                      var dbi = new GlideDBConfiguration.getDBI(tableName);


                      gs.print(new GlideDBIndex(dbi).drop(idx));


                      dbi.close();


              }


              td.close();


      }


}


Hi Dan,


Your script was really helpful, thank you. Could you tell where i can read more about these APIs (i.e. GlideTableDescriptor, GlideDBConfiguration, etc), as i can't find it in official API documentation ( https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=server )