• Create Multiple Indexes using an SQL (Access 2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Create Multiple Indexes using an SQL (Access 2003)

    Author
    Topic
    #440434

    I’m attempting to create a table and indexes against certain fields in the table with the following.

    ‘Create T_XStatB
    CurrentDb.Execute “CREATE TABLE T_XStatBX ( ” & _
    “Seq INTEGER, ” & _
    “Val REAL, ” & _
    “FlagTw REAL, ” & _
    “Slope REAL, ” & _
    “SlopeAbs REAL, ” & _
    “Crossover INTEGER);”

    ‘Create Indexes
    CurrentDb.Execute “CREATE INDEX StatBIndex ” & _
    “ON T_XStatBX (Val,FlagTW);”

    I have no problem creating the table and fields in the table along with a single field index, but when I try to include multiple field indexes using a single SQL (i.e. (Val,FlagTW)), it doesn’t work. Am I doing something wrong?

    Thanks in advance for any help!
    Drew

    Viewing 0 reply threads
    Author
    Replies
    • #1055151

      The SQL looks OK. When I run it in my test database, it *does* create a composite index on two fields. Do you get an error message, and if so, what does it say?

      • #1055153

        I don’t get an error message. When I ‘Design’ on the table that was created (T_XStatBX), the ‘Indexed’ field/property indicates ‘No’.

        Thanks,
        Drew

        • #1055154

          For composite indexes, you must look at the Indexes window: select View | Indexes. The individual fields aren’t indexed.

          If you wanted to create separate indexes on Val and on FlagTw, you should use two separate CREATE INDEX statements, using a different index name for each.

          • #1055156

            Ahhhhh…Thank you
            What’s the difference between having composite verses separate indexes? I will be running multiple SQL’s against this table and the two field (Val and FlagTw) will be used in my criteria. I would like this to be as efficient as possible.

            Regards,
            Drew

            • #1055160

              A composite index means that the Jet Engine keeps track of pairs (or triples, or …) of values (one from FieldA, the other from FieldB), instead of values from a single field.
              In particular, if you create a unique composite index, the values from each field may contain duplicates, but the combinations must be unique. For example, you could have

              FieldA FieldB
              1 4
              1 6
              1 13
              2 1
              2 4
              2 7
              3 6
              3 9
              3 13

              This kind of index is often used in the join table of a many-to-many relationship. Say you have students and classes. Each student can attend several classes, and many students can attend the same class, but the combination of a student and a class should be unique: a student cannot attend the same class twice at the same time.

    Viewing 0 reply threads
    Reply To: Create Multiple Indexes using an SQL (Access 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: