Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7309151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:41:22+00:00 2026-05-28T23:41:22+00:00

My table Customers has a field UserID which is indexed. Now when I am

  • 0

My table Customers has a field UserID which is indexed.

enter image description here

Now when I am dropping this Field from delphi, I am getting EOleExecption as its a indexed field.
I tried with following code:

ObjCustomers := TADOTable.Create(nil);    
ObjCustomers.Connection := Connection;        
ObjCustomers.TableName := 'Customers';
ObjCustomers.Open;

if (ObjCustomers.FindField('UserID').IsIndexField) then
begin      
  ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);    
end;

But this Tfield.IsIndexField is coming up False for this case.
Further I dont wanna do something like this:

try      
  ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);    
except 
  on E: exception do    
end;

Is there any way so that I can check whether the field is Indexed, before executing SQL query?

Thankx in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:41:36+00:00Added an answer on May 28, 2026 at 11:41 pm

    GetIsIndexField is not implemented by TADODataSet, and the result will be False.

    Use TADOConnection.OpenSchema to retrieves table indexes:

    var DataSet: TADODataSet;
    
    DataSet := TADODataSet.Create(nil);
    try
      Connection.OpenSchema(siIndexes, VarArrayOf([Unassigned, Unassigned, Unassigned, Unassigned, 'Customers']), EmptyParam, DataSet);
      while not DataSet.Eof do begin
        ShowMessage(DataSet.FieldByName('INDEX_NAME').AsString);
        DataSet.Next;
      end;
    finally
      DataSet.Free;
    end;
    

    To make this answer complete:
    As suggested by TLama you can use the TADODataSet method GetIndexNames.
    ADO is internally using Command.ActiveConnection.OpenSchema(adSchemaIndexes...

    function IsIndexField(DataSet: TADODataSet; FieldName: string): Boolean;
    var
      SL: TStringList;
    begin
      SL := TStringList.Create;
      try
        DataSet.GetIndexNames(SL);
        Result := SL.IndexOf(FieldName) <> -1;
      finally
        SL.Free;
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      ObjCustomers: TADOTable;
    begin
      ObjCustomers := TADOTable.Create(nil);
      ObjCustomers.Connection := Connection;
      ObjCustomers.TableName := 'Customers';
    
      if IsIndexField(TADODataSet(ObjCustomers), 'UserID') then
      begin
        Showmessage('Index');
        Connection.Execute('DROP INDEX UserID ON Customers');
      end
      else
        Showmessage('Not Index');
    
      // ObjCustomers.Open;
      ObjCustomers.Free;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Customer table which has a PrimaryContactId field and a
I've a table which has customers names along with the products they purchased with
Lets say I have one table called REVIEWS This table has Reviews that customers
I have a customer table, which has a field categories. It's a string holding
I have 2 tables , table 1 has a field which contains prefixes for
I have a table Customers with a CustomerId field, and a table of Publications
This is the constraint I have on the Customers table. ALTER TABLE Customers ADD
I have a query to insert a row into a table, which has a
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have a customers table with ID (auto_inc), name, ... and customer_code fields. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.