我的指数出了什么问题?

时间:2013-10-22 11:35:13

标签: mysql

我使用excel vba来执行数据导入作业,并使用加载数据语法。

每次,我都会导入800多个.csv文件。

数据导入正确。

但是,我在导入完成后通过phpmyadmin检查索引,我发现系统将

创建更多不存在的索引组。

例如:

我有下面的索引“ID”表(3组)

ID  | Number
1   |  10
2   |  30
3   |  15

我导入以下csv文件

ID  |   number
1   |  5
2   |  7

导入后,我会得到4组的索引“ID”,但它应该是3。

我可以通过使用优化表语法来解决这个问题。

但有人可以告诉我为什么会这样吗? THX

以下是我的vba代码供参考:

Dim oConn As ADODB.Connection
Dim myRS As ADODB.Recordset
Dim mySQL As String, FilePath As String, customer_ID As String, Trade_Date As String
Dim i As Integer


    Set oConn = New ADODB.Connection
    Set myRS = New ADODB.Recordset
    oConn.Open "DRIVER={MySQL ODBC 5.2a Driver};" & "SERVER=localhost;" & "DATABASE=stock;" & "USER=root;" & "PASSWORD=xxxx;" & "Option=3"
    Trade_Date = Format(Date, "YYYYMMDD")

    With Worksheets(1)
    For i = 2 To .Range("A65536").End(xlUp).Row

        Customer_ID = .Cells(i, 1)
        FilePath = "D:\Data\" & Trade_Date & "\" & customer_ID & "_" & Trade_Date & ".csv"
        If Dir(FilePath) <> "" Then

            FilePath = "'D://dir//" & Trade_Date & "//" & customer_ID & "_" & Trade_Date & ".csv'"
            mySQL = "load data infile " & FilePath & " into table `deal_record`  character set big5 fields terminated by ',' "
            myRS.Open mySQL, oConn, adOpenDynamic, adLockOptimistic

        End If
    Next i
    .Cells(2, 8) = Trade_Date
    End With

    Set oConn = Nothing
    Set myRS = Nothing

End Sub

0 个答案:

没有答案