Board index » delphi » Remove a primary index

Remove a primary index


2006-07-27 12:14:13 AM
delphi106
Hi
Delphi4 with Paradox tables
I have a Paradox table with a field called 'ID', this is a primary Index. I
now need to remove this primary index but leave the field intact with the
data...is this possible using AlterTable statement?
Many thanks
Kind Regards
Glenn Greatwood
 
 

Re:Remove a primary index

See DROP INDEX in the Local SQL help file.
--
Bill Todd (TeamB)
 

Re:Remove a primary index

DropIndex( 'alias', 'tablename', '' ); // Will drop the primary
index....(I think....)
function DropIndex( Alias, Table, IndexName: String ): Boolean;
var
ATable: TTable;
begin
Result := True;
ATable := TTable.Create( nil );
try
ATable.DatabaseName := Alias;
ATable.TableName := Table;
ATable.DeleteIndex( IndexName );
finally
FreeAndNil( ATable );
end;
end;
Glenn Greatwood writes:
Quote
Hi

Delphi4 with Paradox tables

I have a Paradox table with a field called 'ID', this is a primary Index. I
now need to remove this primary index but leave the field intact with the
data...is this possible using AlterTable statement?

Many thanks

Kind Regards

Glenn Greatwood



 

Re:Remove a primary index

That's great chaps thanks, next problem is I now need to define a new
primary index?
The table name is scheduler.db and the fieldname for the primary index is
GUIDID
Amongst other methods, I have tried the following that doesn't work
(capability not supported)
//create new primary index
With UpdateTables do//
begin
Sql.Clear;
Sql.Add('Alter Table '+Chr(39)+Data+Chr(39));
Sql.Add('ADD PRIMARY KEY (GUIDID)');
ExecSql;
end;
Where UpdateTables is a TQuery and Data is a string set to
'cxSchedulerTable.DB'.
Many thanks for your time
Glenn
"Brian Bushay TeamB" <XXXX@XXXXX.COM>writes
Quote

>Delphi4 with Paradox tables
>
>I have a Paradox table with a field called 'ID', this is a primary Index.
>I
>now need to remove this primary index but leave the field intact with the
>data...is this possible using AlterTable statement?

use
DROP INDEX YourTableName.PRIMARY


--
Brian Bushay (TeamB)
XXXX@XXXXX.COM
 

Re:Remove a primary index

See TTable.AddIndex in the on-line help.
--
Bill Todd (TeamB)
 

Re:Remove a primary index

Thanks Bill
I can call
ScheduleItems.AddIndex('Test', 'GUIDID',[], 'GUIDID');
(where ScheduleItems is a TTable) and create a secondary index called
test....however what I need is a primary index, if that is the right
terminology, or a keyed index? (I can achieve what I require using Database
Desktop and pushing the space bar in the key column when in restructure).
Thanks
Glenn
"Bill Todd" <XXXX@XXXXX.COM>writes
Quote
See TTable.AddIndex in the on-line help.

--
Bill Todd (TeamB)
 

Re:Remove a primary index

The primary index for a Paradox table has no name so if you pass an
empty string as the index name you will get a primary index.
--
Bill Todd (TeamB)
 

Re:Remove a primary index

Thank you Bill
That works and I am one step nearer, however the field I wish to use as my
primary index is only just created in my code immediately before my AddIndex
statement and is so at the end of the 'Field Roster' definition. Can I
programmatically move it to the top of the 'Field Roster' somehow? as this
is where the primary index must be?
Thanks
Glenn
"Bill Todd" <XXXX@XXXXX.COM>writes
Quote
The primary index for a Paradox table has no name so if you pass an
empty string as the index name you will get a primary index.

--
Bill Todd (TeamB)
 

Re:Remove a primary index

Glenn Greatwood writes:
Quote
Can I programmatically move it to the top of the 'Field Roster'
somehow? as this is where the primary index must be?
You can but it is not easy. You have to use the BDE API function
DbiDoRestructure. There is some information available at
info.borland.com/devsupport/bde/bdeapiex. If I was trying to do this I
would search for an example using Google and Google Groups and just
copy it.
--
Bill Todd (TeamB)
 

Re:Remove a primary index

The primary index cannot be dropped and recreated while secondary indexes
exist. you will have to:
-Drop all secondary indexes.
-Drop the primary index.
-Create a new primary index.
-Recreate the secondary indexes.
Sorry if I am stating the obvious, but it sounds like you were trying
to do things differently from that.
Rick Carter
XXXX@XXXXX.COM
Chair, Delphi/Paradox SIG, Cincinnati PC Users Group
--- posted by geoForum on delphi.newswhat.com