?
Solved

Making an Index on Database

Posted on 2002-06-23
9
Medium Priority
?
179 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

764 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