Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Database Efficiency

    What is the most efficient way to build an extract database?

    Specifically, I want to read, via ODBC, one non-MS-Access database table
    with dozens of fields and hundreds of rows and update an initialized
    MS-Access database table with only a couple of fields from all rows.

    Is there a more efficient way than the following? Watch for word-wrap.

    '*
    '* Declare Constants
    '*
    Const cMDB = "MSAccess.mdb"
    Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    '*
    Const adCmdTable = &H0002
    ' Const adExecuteNoRecords = ?
    Const adLockOptimistic = 3
    Const adOpenKeySet = 1
    '*
    '* Declare Variables
    '*
    Dim strSQ1
    strSQ1 = "SELECT CustomerNumber, CustomerName"
    strSQ1 = strSQ1 & " FROM AR1_CustomerMaster"
    Dim strSQ2
    strSQ2 = "INSERT INTO AR1_CustomerMaster"
    strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
    strSQ2 = strSQ2 & " VALUES (#1, #2)"
    '*
    '* Declare Objects
    '*
    Dim objAD1
    Set objAD1 = CreateObject("ADODB.Connection")
    objAD1.Open "ODBC_System_DSN"
    Dim objRS1
    Set objRS1 = objAD1.Execute(strSQ1)
    '*
    Dim objAD2
    Set objAD2 = CreateObject("ADODB.Connection")
    objAD2.Open cDSN & Server.MapPath(cMDB)
    Dim objRS2
    '*
    '* Process Each Row
    '*
    Do Until objRS1.EOF
    strSQ2 = Replace(strSQ2,"#1",objRS1("CustomerNumber"))
    strSQ2 = Replace(strSQ2,"#2",objRS1("CustomerName"))
    objAD2.Execute strSQ2, , 129 '= adExecuteNoRecords + adCmdText
    objRS1.MoveNext
    Loop
    '*
    '* Destroy Objects
    '*
    Set objRS1 = Nothing
    Set objAD2 = Nothing
    Set objAD1 = Nothing

    The above (in part) is from [url]http://www.aspfaq.com/show.asp?id=2191[/url]


    Would the following be better (doubtfully) than INSERT?

    Set objRS2 = Server.CreateObject("ADODB.Recordset")
    objRS2.Open "AR1_CustomerMaster", objAD2, adOpenKeySet,
    adLockOptimistic, adCmdTable
    objRS2.AddNew
    objRS2("CustomerNumber") = objRS1("CustomerNumber")
    objRS2("CustomerName") = objRS1("CustomerName")
    objRS2.Update
    Set objRS2 = Nothing


    Is there a way to do the SELECT and INSERT in a single SQL statement?


    Also, what is the value of "adExecuteNoRecords"?
    It isn't in the include file "ADOVBS.INC".

    Thanks in advance.



    McKirahan Guest

  2. Similar Questions and Discussions

    1. Web Site Efficiency
      Hope i'm in the right group. I'm developing a small non-commercial website to run on windows 2000 pro with IIS. How many simultaneous users (approx)...
    2. Efficiency question
      I am writing an SQL statement to display the most recent articles posted into a database. I know that I can specify the max rows and use "order by...
    3. loading classes and efficiency
      Hi there i was wondering is it more efficient to load class files and objects when needed per page or is it ok to include them in my main include...
    4. Custom Paging Efficiency
      Hello, I'm trying to implement custom paging. At the moment I can get the first page to display. When I click on the number 2 it takes forever to...
    5. Marshal efficiency
      Folks, As an intermediate step in a small software system that performs a large amount of data gathering, I am using Marshal to store processed...
  3. #2

    Default Re: Database Efficiency

    McKirahan wrote:
    > What is the most efficient way to build an extract database?
    >
    > Specifically, I want to read, via ODBC, one non-MS-Access database
    > table with dozens of fields and hundreds of rows and update an
    > initialized MS-Access database table with only a couple of fields
    > from all rows.
    >
    > Is there a more efficient way than the following? Watch for
    > word-wrap.
    >
    > '*
    > '* Declare Constants
    > '*
    > Const cMDB = "MSAccess.mdb"
    > Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    > '*
    > Const adCmdTable = &H0002
    > ' Const adExecuteNoRecords = ?
    Const adExecuteNoRecords = 128
    > Const adLockOptimistic = 3
    > Const adOpenKeySet = 1
    > '*
    > '* Declare Variables
    > '*
    > Dim strSQ1
    > strSQ1 = "SELECT CustomerNumber, CustomerName"
    > strSQ1 = strSQ1 & " FROM AR1_CustomerMaster"
    > Dim strSQ2
    > strSQ2 = "INSERT INTO AR1_CustomerMaster"
    > strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
    > strSQ2 = strSQ2 & " VALUES (#1, #2)"
    > '*
    > '* Declare Objects
    > '*
    > Dim objAD1
    > Set objAD1 = CreateObject("ADODB.Connection")
    > objAD1.Open "ODBC_System_DSN"
    > Dim objRS1
    > Set objRS1 = objAD1.Execute(strSQ1)
    > '*
    > Dim objAD2
    > Set objAD2 = CreateObject("ADODB.Connection")
    > objAD2.Open cDSN & Server.MapPath(cMDB)
    > Dim objRS2
    > '*
    > '* Process Each Row
    > '*
    > Do Until objRS1.EOF
    > strSQ2 = Replace(strSQ2,"#1",objRS1("CustomerNumber"))
    > strSQ2 = Replace(strSQ2,"#2",objRS1("CustomerName"))
    > objAD2.Execute strSQ2, , 129 '= adExecuteNoRecords + adCmdText
    > objRS1.MoveNext
    > Loop
    > '*
    > '* Destroy Objects
    > '*
    > Set objRS1 = Nothing
    > Set objAD2 = Nothing
    > Set objAD1 = Nothing
    >
    > The above (in part) is from [url]http://www.aspfaq.com/show.asp?id=2191[/url]
    >
    >
    > Would the following be better (doubtfully) than INSERT?
    No, INSERT will always be faster.
    >
    > Set objRS2 = Server.CreateObject("ADODB.Recordset")
    > objRS2.Open "AR1_CustomerMaster", objAD2, adOpenKeySet,
    > adLockOptimistic, adCmdTable
    > objRS2.AddNew
    > objRS2("CustomerNumber") = objRS1("CustomerNumber")
    > objRS2("CustomerName") = objRS1("CustomerName")
    > objRS2.Update
    > Set objRS2 = Nothing
    >
    >
    > Is there a way to do the SELECT and INSERT in a single SQL statement?
    Yes, there are two ways:

    1. You can create a linked table in your Access database and do a simple:
    strSQ2 = "INSERT INTO AR1_CustomerMaster"
    strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
    strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
    strSQ2 = strSQ2 & " FROM AR1_CustomerMaster_lnk"



    2. You can use an IN clause in your SELECT statement:

    Dim strSQ2
    strSQ2 = "INSERT INTO AR1_CustomerMaster"
    strSQ2 = strSQ2 & " (CustomerNumber, CustomerNumber)"
    strSQ2 = strSQ2 & " SELECT CustomerNumber, CustomerName"
    strSQ2 = strSQ2 & " FROM AR1_CustomerMaster "
    strSQ2 = strSQ2 & " IN '' [ODBC; DSN=ODBC_System_DSN;]"

    >
    >
    > Also, what is the value of "adExecuteNoRecords"?
    When you execute a statement that does not return records, you need to tell
    the Command object (yes, a Command object is being used by ADO here) to skip
    the creation of a recordset object. If you do not use "adExecuteNoRecords",
    it will create a recordset object even though your query does not return any
    records.


    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139