ADO Scallable Search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian Parker

    #1

    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. <adrian.parker@ sympatico.ca>
    Want to know the purpose of life? I'd be happy to share it with you...


  • Stephane Richard

    #2
    Re: ADO Scallable Search

    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 <TempTableNam e> * 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 <TempTableNam e> ORDER BY <SortField(s) >

    And present that table.
    --
    Stéphane Richard
    "Ada World" Webmaster



    "Adrian Parker" <no@addy.com> wrote in message
    news:X1bdb.9089 $1H3.532780@new s20.bellglobal. com...[color=blue]
    > 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[/color]
    moving[color=blue]
    > on to the next table etc?
    >
    > That seems a very brute force method to me.
    >
    >
    >
    > <Ade
    > --
    > Adrian Parker. Ordained priest. <adrian.parker@ sympatico.ca>
    > Want to know the purpose of life? I'd be happy to share it with you...
    >
    >[/color]


    Comment

    • Adrian Parker

      #3
      Re: ADO Scallable Search


      "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
      news:Tkcdb.8646 $yU5.2564@nwrdn y01.gnilink.net ...
      [color=blue]
      > You could do it all in SQL and create a temp table for the results. if[/color]
      all[color=blue]
      > 200 Table have the same structure (which I assume they do here, you'd need[/color]
      a[color=blue]
      > 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[/color]
      you[color=blue]
      > a lot of time for this :-).[/color]

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

      [color=blue]
      > SELECT INTO <TempTableNam e> * FROM <TableName> WHERE <ListOfCriteria >
      >
      > Depending on Database type (MySQL, SQL Server, Oracle, Firebird[/color]
      (Interbase),[color=blue]
      > 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.[/color]

      I am indeed using Access though. Any ideas?


      <snip>


      Adrian


      Comment

      • Stephane Richard

        #4
        Re: ADO Scallable Search

        in a VB loop, execute the first query that I showed in my last message

        Select Into <TempTableNam e> * FROM <TableName> WHERE <Conditions>

        Making sure <TempTableNam e> 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 <TempTableNam e> ORDER BY <Sort order>" and you should be set.



        --
        Stéphane Richard
        "Ada World" Webmaster



        "Adrian Parker" <no@addy.com> wrote in message
        news:r1kdb.9245 $1H3.561646@new s20.bellglobal. com...[color=blue]
        >
        > "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
        > news:Tkcdb.8646 $yU5.2564@nwrdn y01.gnilink.net ...
        >[color=green]
        > > You could do it all in SQL and create a temp table for the results. if[/color]
        > all[color=green]
        > > 200 Table have the same structure (which I assume they do here, you'd[/color][/color]
        need[color=blue]
        > a[color=green]
        > > series of (Idealy adding perhaps a SchoolID field to a table and[/color][/color]
        filtering[color=blue][color=green]
        > > all records by School ID instead of having a table per school would save[/color]
        > you[color=green]
        > > a lot of time for this :-).[/color]
        >
        > Ya, but try convincing the entire Leeds & Grenville schoolboard that they
        > have to change their existing format :)
        >
        >[color=green]
        > > SELECT INTO <TempTableNam e> * FROM <TableName> WHERE <ListOfCriteria >
        > >
        > > Depending on Database type (MySQL, SQL Server, Oracle, Firebird[/color]
        > (Interbase),[color=green]
        > > 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.[/color]
        >
        > I am indeed using Access though. Any ideas?
        >
        >
        > <snip>
        >
        >
        > Adrian
        >
        >[/color]


        Comment

        • Steve Gerrard

          #5
          Re: ADO Scallable Search

          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:r1kdb.9245 $1H3.561646@new s20.bellglobal. com...[color=blue]
          >
          > "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
          > news:Tkcdb.8646 $yU5.2564@nwrdn y01.gnilink.net ...
          >[color=green]
          > > You could do it all in SQL and create a temp table for the results. if[/color]
          > all[color=green]
          > > 200 Table have the same structure (which I assume they do here, you'd need[/color]
          > a[color=green]
          > > 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[/color]
          > you[color=green]
          > > a lot of time for this :-).[/color]
          >
          > Ya, but try convincing the entire Leeds & Grenville schoolboard that they
          > have to change their existing format :)
          >
          >[color=green]
          > > SELECT INTO <TempTableNam e> * FROM <TableName> WHERE <ListOfCriteria >
          > >
          > > Depending on Database type (MySQL, SQL Server, Oracle, Firebird[/color]
          > (Interbase),[color=green]
          > > 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.[/color]
          >
          > I am indeed using Access though. Any ideas?
          >
          >
          > <snip>
          >
          >
          > Adrian
          >
          >[/color]


          Comment

          • Adrian Parker

            #6
            Re: ADO Scallable Search


            "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
            news:5kkdb.9043 $yU5.8714@nwrdn y01.gnilink.net ...[color=blue]
            > in a VB loop, execute the first query that I showed in my last message
            >
            > Select Into <TempTableNam e> * FROM <TableName> WHERE <Conditions>
            >
            > Making sure <TempTableNam e> 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 <TempTableNam e> ORDER BY <Sort order>" and you should be[/color]
            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


            Comment

            • Adrian Parker

              #7
              Re: ADO Scallable Search


              "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
              news:5kkdb.9043 $yU5.8714@nwrdn y01.gnilink.net ...[color=blue]
              > in a VB loop, execute the first query that I showed in my last message
              >
              > Select Into <TempTableNam e> * FROM <TableName> WHERE <Conditions>
              >
              > Making sure <TempTableNam e> 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 <TempTableNam e> ORDER BY <Sort order>" and you should be[/color]
              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


              Comment

              • Adrian Parker

                #8
                Re: ADO Scallable Search


                "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message
                news:5X2dncrp0N oFQOiiU-KYvQ@comcast.co m...[color=blue]
                > If "Ya, but try..." means that yes, the tables are the same structure, but[/color]
                no,[color=blue]
                > you can't make a single table out of them (the correct design), then you[/color]
                might[color=blue]
                > consider a Union query. A Union query requires that each Select statement[/color]
                return[color=blue]
                > 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.[/color]

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


                Adrian


                Comment

                • preben nielsen

                  #9
                  Re: ADO Scallable Search


                  "Adrian Parker" <no@addy.com> skrev i en meddelelse
                  news:X1bdb.9089 $1H3.532780@new s20.bellglobal. com...[color=blue]
                  > I have a database of 200+ tables (two tables per school), each[/color]
                  with 100 -[color=blue]
                  > 4000 records (one record per student). A contract I'm looking[/color]
                  at wants to

                  That sounds like a design flaw to me :-/


                  --
                  /\ preben nielsen
                  \/\ prel@post.tele. dk


                  Comment

                  • Steve Gerrard

                    #10
                    Re: ADO Scallable Search


                    "Adrian Parker" <no@addy.com> wrote in message
                    news:Nnodb.1169 8$1H3.578186@ne ws20.bellglobal .com...[color=blue]
                    >
                    > "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message
                    > news:5X2dncrp0N oFQOiiU-KYvQ@comcast.co m...[color=green]
                    > > If "Ya, but try..." means that yes, the tables are the same structure, but[/color]
                    > no,[color=green]
                    > > you can't make a single table out of them (the correct design), then you[/color]
                    > might[color=green]
                    > > consider a Union query. A Union query requires that each Select statement[/color]
                    > return[color=green]
                    > > 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.[/color]
                    >
                    > How do I run this from VB though without using an ADO object?
                    >
                    >
                    > Adrian
                    >
                    >[/color]

                    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.



                    Comment

                    • Steve Gerrard

                      #11
                      Re: ADO Scallable Search

                      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(st rYourSQLActionT ext) for
                      "action queries" (ones that do something). You can also make a new ADO Recordset
                      object, and do rsMyRecs = conn.Execute(st rYourSQLSelectT ext) for queries that
                      return records. strYourSQLSelec tText could be a union query, for instance.

                      "Adrian Parker" <no@addy.com> wrote in message
                      news:Nnodb.1169 8$1H3.578186@ne ws20.bellglobal .com...[color=blue]
                      >
                      > "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message
                      > news:5X2dncrp0N oFQOiiU-KYvQ@comcast.co m...[color=green]
                      > > If "Ya, but try..." means that yes, the tables are the same structure, but[/color]
                      > no,[color=green]
                      > > you can't make a single table out of them (the correct design), then you[/color]
                      > might[color=green]
                      > > consider a Union query. A Union query requires that each Select statement[/color]
                      > return[color=green]
                      > > 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.[/color]
                      >
                      > How do I run this from VB though without using an ADO object?
                      >
                      >
                      > Adrian
                      >
                      >[/color]


                      Comment

                      • Shiela Marie
                        New Member
                        • Sep 2005
                        • 1

                        #12
                        Re: ADO Scallable Search

                        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.

                        Comment

                        Working...