Solved

Making an Index on Database

Posted on 2002-06-23
9
168 Views
Last Modified: 2010-04-04
How can i make an index of a table (INTERBASE)?

here is my code to create a table how can i add an index for the username and employee ID

Procedure T_DataModule1.CreateUsersDB(NameFile: string);
begin
 Try
 With wwQuery1 do
 begin
  Active := false;
  DatabaseName :=  _Main.DatabaseName;
  SessionName  :=  _Main.sSessionName;
  SQL.Clear;
  SQL.Add('CREATE TABLE '+NameFile);
  SQL.Add('(');
  SQL.Add('EmplyeeID      VARCHAR(10),');
  SQL.Add('sUserName     VARCHAR(10),');
  SQL.Add('sPassWord     VARCHAR(10),');
  SQL.Add('AccessRights  VARCHAR(30)');
  SQL.Add(');');
  ExecSQL;
 end;
 except
  //do nothing
 end;
end;
0
Comment
Question by:girlswants_me
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7102771
just from head

create [unique] index index_name on tablename (fieldnamelist)

[] means optional

meikl ;-)
0
 

Author Comment

by:girlswants_me
ID: 7102842
can you give me codes for it
0
 

Author Comment

by:girlswants_me
ID: 7102843
for the username and employee ID
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7102886
query1.sql.text := 'create unique index aname on tablename (employeeID, sUsername)');
query1.execSQL;

tablename and aname must be replaced by your values

not tested

meikl ;-)
0
 

Author Comment

by:girlswants_me
ID: 7102897
that only have 1 index how about i like to have both
employeeID and sUsername having a Unique Index each.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7102918
query1.sql.text := 'create unique index aname on tablename (sUsername)');
query1.execSQL;

query1.sql.text := 'create unique index aname on tablename (employeeID)');
query1.execSQL;

tablename and aname must be replaced by your values

not tested

meikl ;-)
0
 

Author Comment

by:girlswants_me
ID: 7123791
whats wrong with my code?


Try
 With wwQuery1 do
 begin
  Active := false;
  DatabaseName :=  _Main.DatabaseName;
  SessionName  :=  _Main.sSessionName;
  SQL.Clear;
  SQL.Add('CREATE TABLE '+NameFile);
  SQL.Add('(');
  SQL.Add('EmplyeeID      VARCHAR(10),');
  SQL.Add('sUserName     VARCHAR(10),');
  SQL.Add('sPassWord     VARCHAR(10),');
  SQL.Add('AccessRights  VARCHAR(30)');
  SQL.Add(');');
  ExecSQL;

{  SQL.clear;
  SQL.Add('CREATE INDEX NAMEX ON '+NameFile+' (EmplyeeID,sUserName)');
  ExecSQL;}

  sql.text := 'create unique index _Username   on '+NameFile+' (sUserName)';
  execSQL;

  sql.text := 'create unique index _employeeID on '+NameFile+' (EmplyeeID)';
  execSQL;


 end;
 except
  //do nothing
 end;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7123845
what error do you get?
0
 

Author Comment

by:girlswants_me
ID: 7125851
Thank you its my code have error. thanks a lot for the help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question