Solved

Making an Index on Database

Posted on 2002-06-23
9
158 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
Comment Utility
just from head

create [unique] index index_name on tablename (fieldnamelist)

[] means optional

meikl ;-)
0
 

Author Comment

by:girlswants_me
Comment Utility
can you give me codes for it
0
 

Author Comment

by:girlswants_me
Comment Utility
for the username and employee ID
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:girlswants_me
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
what error do you get?
0
 

Author Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now