首页  编辑  

用Dephi程序维护Paradox数据表的索引

Tags: /超级猛料/Database.数据库相关/Paradox & dBase/   Date Created:

ݿ,ļڸݲѯٶžص,ʹļԼݿӦó,һԷϵ.Ӧù,ûIJѯǶֶ,ܸûѯѡ,ڱ֤Ӧó,Ǻа.,ͣ¹ʺݿеļδʱ,ʱӦóٳϢ,ɽʹûĴѩϼ˪.,̬άݿļ,ʹݿӦóȶԺͿɿ.

߽DelphiгõParadoxݿΪ,ݿļĶ̬ά.

ParadoxݱΪ(Primary Index)ؼ(Primary Key)ʹ(Secondary Index),Ӧ.PXļ,Ӧ.XG*.YG*ļ.

һ.

(1)Table.AddIndexʵ

:AddIndex( IndexName,FieldNames,Options )

:(Delphi)

IndexName:,ָʱ.

FieldNames:,ָ,֮÷ֺŸ,'Field1;Field2;Field3'

Options:ѡ,Ϊ[ixPrimary,ixUnique,ixDescending,ixCaseInsensitive,ixExpression]

:

ixPrimary : Ϊ(dBaseݱ).

ixUnique : ظֵ.

ixDescending: .

ixCaseInsensitive: ʱԴСд(dBaseݱ).

ixExpression: ʽ(Delphi3.0,dBaseݱ).

ixNonMaintained: ǷҪBDEԶά(Delphi1.0).

һ:

һͨѶ¼ݱMyComm.DB(ΪParadox)ڱĿ¼d:\mynote,ֽһ(ΪID)һ(ΪIDName,ΪNameIndex).

with table1 do

begin

close;

Exclusive := true;

DatabaseName := 'd:\MyNote';

TableName := 'MyComm.DB';

Open;

{ }

AddIndex('','ID',[ixPrimary]);

{ }

AddIndex('NameIndex','ID;Name',[]);

close;

end;

(2)SQLʵ

Paradoxݱ˵,SQLֻܽ.SQL﷨,:

Create Index IndexName On TableName(IndexField1,IndexField2,..)

:

IndexNameΪһ,MySecIndex1.

TableNameΪӦݱ,MyTable.

TableNameΪб,Բ,֮öŸ.

һ:

һͨѶ¼ݱMyComm.DB(ΪParadox)ڱĿ¼d:\mynote,ֽһ(ΪIDName,ΪNameIndex).

with query1 do

begin

close;

DatabaseName := 'd:\MyNote';

{ NameIndex }

sql.clear;

sql.add( 'Create Index NameIndex On MyComm(ID,Name)' );

execSql;

end;

. ɾ

(1)Table.DeleteIndexʵ

DeleteIndexֻɾ.

:DeleteIndex( IndexName )

:(Delphi)

IndexName:.

һ:

һͨѶ¼ݱMyComm.DB(ΪParadox)ڱĿ¼d:\mynote,һ(ΪIDName,ΪNameIndex),ɾ֮.

with table1 do

begin

close;

Exclusive := true;

DatabaseName := 'd:\MyNote';

TableName := 'MyComm.DB';

Open;

{ ɾ }

DeleteIndex('NameIndex');

close;

end;

(2)SQLʵ

SQL﷨,ɾ:

Drop Index TableName.IndexName

Ҫɾʱ,IndexNameΪһ,'MyTable.MySecIndex1'.

Ҫɾʱ,IndexNameΪ'primary','MyTable.primary';ֵע,

ɾɹ,ݱдҲԶɾ.

һ:

һͨѶ¼ݱMyComm.DB(ΪParadox)ڱĿ¼d:\mynote,Ѷһ(ΪID)һ(ΪIDName,ΪNameIndex).Ϊ,Ҫɾ,Ա.

with query1 do

begin

close;

DatabaseName := 'd:\MyNote';

{ ɾNameIndex }

sql.clear;

sql.add( 'Drop Index MyComm.NameIndex' );

execSql;

{ ɾ }

sql.clear;

sql.add( 'Drop Index MyComm.Primary' );

execSql;

end;

. ע:

(1) ʱ,Ӧ֤ӦݱԶռʽ(Exclusive=true),.

(2) Լ޸ĺ,ҲdBase,Oracleݿݱ.

(3) Ҫ¶ļ,οBDEDbi˵:RegenIndex, RegenIndexes.

(4) ϳDelphi3.0²ͨ