Generate sql insert script from excel worksheet

后端 未结 13 1022
情深已故
情深已故 2020-11-28 18:05

I have a large excel worksheet that I want to add to my database.

Can I generate an SQL insert script from this excel worksheet?

13条回答
  •  旧巷少年郎
    2020-11-28 18:31

    You can use the following excel statement:

    ="INSERT INTO table_name(`"&$A$1&"`,`"&$B$1&"`,`"&$C$1&"`, `"&$D$1&"`) VALUES('"&SUBSTITUTE(A2, "'", "\'")&"','"&SUBSTITUTE(B2, "'", "\'")&"','"&SUBSTITUTE(C2, "'", "\'")&"', "&D2&");"
    

    This improves upon Hart CO's answer as it takes into account column names and gets rid of compile errors due to quotes in the column. The final column is an example of a numeric value column, without quotes.

提交回复
热议问题