469,306 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

ADO Scallable Search

I have a database of 200+ tables (two tables per school), each with 100 -
4000 records (one record per student). A contract I'm looking at wants to
be able to do a search across all the tables, searching for values a user
inputs via a Search form.

I have a solution, but I don't think it'll work on large scales.

Is there a better bet then querying table 1, finding matching values and
writing those records into an ADO variable, closing that table, then moving
on to the next table etc?

That seems a very brute force method to me.

<Ade
--
Adrian Parker. Ordained priest. <ad***********@sympatico.ca>
Want to know the purpose of life? I'd be happy to share it with you...
Jul 17 '05 #1
11 3630
You could do it all in SQL and create a temp table for the results. if all
200 Table have the same structure (which I assume they do here, you'd need a
series of (Idealy adding perhaps a SchoolID field to a table and filtering
all records by School ID instead of having a table per school would save you
a lot of time for this :-).

SELECT INTO <TempTableName> * FROM <TableName> WHERE <ListOfCriteria>

Depending on Database type (MySQL, SQL Server, Oracle, Firebird (Interbase),
Access) you could put all these queries in a stored procedure (except
Access) and execute that stored procedure passing it the search criteria
from that search form.

Once all queries are executed (or store procedure)

SELECT * FROM <TempTableName> ORDER BY <SortField(s)>

And present that table.
--
Stéphane Richard
"Ada World" Webmaster
http://www.adaworld.com
"Adrian Parker" <no@addy.com> wrote in message
news:X1*******************@news20.bellglobal.com.. .
I have a database of 200+ tables (two tables per school), each with 100 -
4000 records (one record per student). A contract I'm looking at wants to
be able to do a search across all the tables, searching for values a user
inputs via a Search form.

I have a solution, but I don't think it'll work on large scales.

Is there a better bet then querying table 1, finding matching values and
writing those records into an ADO variable, closing that table, then moving on to the next table etc?

That seems a very brute force method to me.

<Ade
--
Adrian Parker. Ordained priest. <ad***********@sympatico.ca>
Want to know the purpose of life? I'd be happy to share it with you...

Jul 17 '05 #2

"Stephane Richard" <st**************@verizon.net> wrote in message
news:Tk*****************@nwrdny01.gnilink.net...
You could do it all in SQL and create a temp table for the results. if all 200 Table have the same structure (which I assume they do here, you'd need a series of (Idealy adding perhaps a SchoolID field to a table and filtering
all records by School ID instead of having a table per school would save you a lot of time for this :-).
Ya, but try convincing the entire Leeds & Grenville schoolboard that they
have to change their existing format :)

SELECT INTO <TempTableName> * FROM <TableName> WHERE <ListOfCriteria>

Depending on Database type (MySQL, SQL Server, Oracle, Firebird (Interbase), Access) you could put all these queries in a stored procedure (except
Access) and execute that stored procedure passing it the search criteria
from that search form.


I am indeed using Access though. Any ideas?
<snip>
Adrian
Jul 17 '05 #3
in a VB loop, execute the first query that I showed in my last message

Select Into <TempTableName> * FROM <TableName> WHERE <Conditions>

Making sure <TempTableName> is the same name for all queries

Once they are all done (which shuold be faster, much faster than using ADO
recordset Objects do insert). (hence right after the loop is done.

Open a recordset Object in dbOpenDynaset mode. with the query

SELECT * from <TempTableName> ORDER BY <Sort order>" and you should be set.

--
Stéphane Richard
"Ada World" Webmaster
http://www.adaworld.com
"Adrian Parker" <no@addy.com> wrote in message
news:r1*******************@news20.bellglobal.com.. .

"Stephane Richard" <st**************@verizon.net> wrote in message
news:Tk*****************@nwrdny01.gnilink.net...
You could do it all in SQL and create a temp table for the results. if all
200 Table have the same structure (which I assume they do here, you'd need a
series of (Idealy adding perhaps a SchoolID field to a table and

filtering all records by School ID instead of having a table per school would save

you
a lot of time for this :-).


Ya, but try convincing the entire Leeds & Grenville schoolboard that they
have to change their existing format :)

SELECT INTO <TempTableName> * FROM <TableName> WHERE <ListOfCriteria>

Depending on Database type (MySQL, SQL Server, Oracle, Firebird

(Interbase),
Access) you could put all these queries in a stored procedure (except
Access) and execute that stored procedure passing it the search criteria
from that search form.


I am indeed using Access though. Any ideas?
<snip>
Adrian

Jul 17 '05 #4
If "Ya, but try..." means that yes, the tables are the same structure, but no,
you can't make a single table out of them (the correct design), then you might
consider a Union query. A Union query requires that each Select statement return
the same fields, in the same order. A sample:

Select StudentName, StudentGrade FROM SchoolATable
UNION
Select StudentName, StudentGrade FROM SchoolBTable
UNION
Select StudentName, StudentGrade FROM SchoolCTable...etc.

In other words, it creates a temporary result set that is essentially the
combined table. You can apply criteria to it as well. I have no idea if
UNION'ing 200 tables is acceptable or not.

----Thought #2

Sometimes you can fake people out and hide the real table structure. If you made
a combined table with a SchoolID field, say call it AllSchools, you can then
create a set of 200 queries, each specifying a specific SchoolID value. If you
name the queries whatever the 200 tables used to be called, no one need be any
the wiser (except you). Stored select queries (or views) are treated the same as
tables by forms, reports, other queries, ADO recordset commands, etc. In fact,
when you open a table "directly", the underlying database engine is just running
the implied query "Select * from TableName" anyway.
"Adrian Parker" <no@addy.com> wrote in message
news:r1*******************@news20.bellglobal.com.. .

"Stephane Richard" <st**************@verizon.net> wrote in message
news:Tk*****************@nwrdny01.gnilink.net...
You could do it all in SQL and create a temp table for the results. if

all
200 Table have the same structure (which I assume they do here, you'd need

a
series of (Idealy adding perhaps a SchoolID field to a table and filtering
all records by School ID instead of having a table per school would save

you
a lot of time for this :-).


Ya, but try convincing the entire Leeds & Grenville schoolboard that they
have to change their existing format :)

SELECT INTO <TempTableName> * FROM <TableName> WHERE <ListOfCriteria>

Depending on Database type (MySQL, SQL Server, Oracle, Firebird

(Interbase),
Access) you could put all these queries in a stored procedure (except
Access) and execute that stored procedure passing it the search criteria
from that search form.


I am indeed using Access though. Any ideas?
<snip>
Adrian

Jul 17 '05 #5

"Stephane Richard" <st**************@verizon.net> wrote in message
news:5k*****************@nwrdny01.gnilink.net...
in a VB loop, execute the first query that I showed in my last message

Select Into <TempTableName> * FROM <TableName> WHERE <Conditions>

Making sure <TempTableName> is the same name for all queries

Once they are all done (which shuold be faster, much faster than using ADO
recordset Objects do insert). (hence right after the loop is done.

Open a recordset Object in dbOpenDynaset mode. with the query

SELECT * from <TempTableName> ORDER BY <Sort order>" and you should be

set.

How slow do you think querying 200+ tables would be, if the average amount
of records was 700?

I'll try as explained. I didn't know that Visual Basic could call SQL
statements without using an ADO object.
Adrian
Jul 17 '05 #6

"Stephane Richard" <st**************@verizon.net> wrote in message
news:5k*****************@nwrdny01.gnilink.net...
in a VB loop, execute the first query that I showed in my last message

Select Into <TempTableName> * FROM <TableName> WHERE <Conditions>

Making sure <TempTableName> is the same name for all queries

Once they are all done (which shuold be faster, much faster than using ADO
recordset Objects do insert). (hence right after the loop is done.

Open a recordset Object in dbOpenDynaset mode. with the query

SELECT * from <TempTableName> ORDER BY <Sort order>" and you should be

set.
Also, how do I get the names of the tables dynamically?

I do not want to write out the names of 200 tables in a config file.

Can I use the usual SHOW TABLES statement?
Adrian
Jul 17 '05 #7

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:5X********************@comcast.com...
If "Ya, but try..." means that yes, the tables are the same structure, but no, you can't make a single table out of them (the correct design), then you might consider a Union query. A Union query requires that each Select statement return the same fields, in the same order. A sample:

Select StudentName, StudentGrade FROM SchoolATable
UNION
Select StudentName, StudentGrade FROM SchoolBTable
UNION
Select StudentName, StudentGrade FROM SchoolCTable...etc.

In other words, it creates a temporary result set that is essentially the
combined table. You can apply criteria to it as well. I have no idea if
UNION'ing 200 tables is acceptable or not.


How do I run this from VB though without using an ADO object?
Adrian
Jul 17 '05 #8

"Adrian Parker" <no@addy.com> skrev i en meddelelse
news:X1*******************@news20.bellglobal.com.. .
I have a database of 200+ tables (two tables per school), each with 100 - 4000 records (one record per student). A contract I'm looking

at wants to

That sounds like a design flaw to me :-/
--
/\ preben nielsen
\/\ pr**@post.tele.dk
Jul 17 '05 #9

"Adrian Parker" <no@addy.com> wrote in message
news:Nn********************@news20.bellglobal.com. ..

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:5X********************@comcast.com...
If "Ya, but try..." means that yes, the tables are the same structure, but

no,
you can't make a single table out of them (the correct design), then you

might
consider a Union query. A Union query requires that each Select statement

return
the same fields, in the same order. A sample:

Select StudentName, StudentGrade FROM SchoolATable
UNION
Select StudentName, StudentGrade FROM SchoolBTable
UNION
Select StudentName, StudentGrade FROM SchoolCTable...etc.

In other words, it creates a temporary result set that is essentially the
combined table. You can apply criteria to it as well. I have no idea if
UNION'ing 200 tables is acceptable or not.


How do I run this from VB though without using an ADO object?
Adrian


Not sure what you mean. ADO is all objects. I think you need at least a
connection and a recordset to do anything.

A union query, such as the one above, can be used in place of a standard select
query as command text or as the the SQL passed to the OpenRecordset method. You
can also construct such a query in Access, which I think you said you were
using. It is in the Query menu of the query designer. Once it is in the Access
database, you can select from it and filter it the same way you would get data
from a table.

Jul 17 '05 #10
Wait a sec. I reread some earlier posts. What Stephane meant about executing
"Select Into" queries, rather than inserting using an object, was that copying
records from one ADO recordset to another would be slower.

To execute a SQL command, you still need to create and open an ADO connection
object. Then you can make calls to conn.Execute(strYourSQLActionText) for
"action queries" (ones that do something). You can also make a new ADO Recordset
object, and do rsMyRecs = conn.Execute(strYourSQLSelectText) for queries that
return records. strYourSQLSelectText could be a union query, for instance.

"Adrian Parker" <no@addy.com> wrote in message
news:Nn********************@news20.bellglobal.com. ..

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:5X********************@comcast.com...
If "Ya, but try..." means that yes, the tables are the same structure, but

no,
you can't make a single table out of them (the correct design), then you

might
consider a Union query. A Union query requires that each Select statement

return
the same fields, in the same order. A sample:

Select StudentName, StudentGrade FROM SchoolATable
UNION
Select StudentName, StudentGrade FROM SchoolBTable
UNION
Select StudentName, StudentGrade FROM SchoolCTable...etc.

In other words, it creates a temporary result set that is essentially the
combined table. You can apply criteria to it as well. I have no idea if
UNION'ing 200 tables is acceptable or not.


How do I run this from VB though without using an ADO object?
Adrian

Jul 17 '05 #11
i have read about your discussion. i think i am having the same problem.
I have a single "members" table containing about 65,000 records. accessing it using a windows 98 computer with 64MB RAM as well as some MHz or 1. something GHZ speed is quite slow. Thus, i decided to chop it off into 26 tables (from memberA - memberZ).

The problem is i don't know what to do inorder to make the accessing of the record faster. I tried UNION but it can only access up to 3 tables.

help please.

PS for additional info, i have a command to search the table by memberName or memberID.
Sep 9 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by R. Rajesh Jeba Anbiah | last post: by
10 posts views Thread by Anand Pillai | last post: by
5 posts views Thread by George | last post: by
28 posts views Thread by joshc | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.