Link to home
Start Free TrialLog in
Avatar of dannywareham
dannywarehamFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Index a table

Hi all

Can you apply an index to a table from code?
I have a table which is imported and dropped each time (because it makes the db 400mb!)
What I'd like to do is create an index on a field (or three) so that subsequent queries run faster.
At the moment, the database update can take 40mins.

Can this be done...?


Danny
Avatar of flavo
flavo
Flag of Australia image

Create Unique Index myID On myTable (myID)

Dave
Hi Danny

why not just delete Yourtable.*   instead of deleting it.


Alan
Avatar of dannywareham

ASKER

Hey Alan - The structure f the table may change from time to time.
It's pulled from another database that our MIS team own. I need it's data, but only to run some calculations - then it can be dumped like a dog-rough girlfriend.

Dave - That creates a unique index. How about an idex of "Yes - duplicates OK"?
Hi Danny,


Sorry error in first post, trying to suggest the concept, rather than syntactical accuracy, well thats my excuse and I'm sticking to it.

CurrentProject.Connection.Execute "DELETE [Yourtable].* FROM [Yourtable]",, adExecuteNoRecords


ps...

sheesh dave I'm trying to keep you busy on your question so I can answer  the new ones... ":0)
ASKER CERTIFIED SOLUTION
Avatar of flavo
flavo
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
LOL!

Have you been getting into that scotch again Alan :-)
Sorry guys, I can't get this to work. I'm in Acc97 on this one...

Create UNIQUE INDEX blah blah   doesn't work (unknown functions)
and
Dim dbs as Database doesn't work either
>> Create UNIQUE INDEX blah blah   doesn't work (unknown functions)

What version of Jet you got 4.0?

>> Dim dbs as Database doesn't work either

Tools -> refrences -> select Microsoft DAO Object Library 3.?
 
thought you was off to bed Dave?

Reaching for another frosty VB from http://www.vb.com.au

know any good sites Dave? <grin>

Hi danny,

Can you post what you've got mate, will try to debug it for you.


Alan
Hi Danny

try this:

Sub someSub()
 CurrentProject.Execute "CREATE INDEX SNameIndex ON table1 (SName)"
 '------------------------------index name-----^---tablename--^--------^--------fieldname
End Sub

Alan
Sorry Danny,

big mistake, cant create an index using currentproject.connection.execute

DoCmd.RunSQL "CREATE INDEX SNameIndex ON table1 (SName)"

Alan
DoCmd.RunSql uses DAO without setting a reference to DAO

Microsoft warns, "The Microsoft Jet database engine doesn't support the use of any DDL statements with databases produced by any other database engine. Use the DAO (Data Access Objects) Create methods instead."

Alan
Guys, I'm gonna abandon this question for the minute...
I'll get the db working at a snail's pace first (it's playing funny buggers at the mo)