Solved

Making an Index on Database

Posted on 2002-06-23
9
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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