Generate sql insert script from excel worksheet

后端 未结 13 1005
情深已故
情深已故 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:19

    Use the ConvertFrom-ExcelToSQLInsert from the ImportExcel in the PowerShell Gallery

    NAME
        ConvertFrom-ExcelToSQLInsert
    SYNTAX
        ConvertFrom-ExcelToSQLInsert [-TableName] <Object> [-Path] <Object> 
          [[-WorkSheetname] <Object>] [[-HeaderRow] <int>] 
          [[-Header] <string[]>] [-NoHeader] [-DataOnly]  [<CommonParameters>]
    PARAMETERS
        -DataOnly
        -Header <string[]>
        -HeaderRow <int>
        -NoHeader
        -Path <Object>
        -TableName <Object>
        -WorkSheetname <Object>
        <CommonParameters>
            This cmdlet supports the common parameters: Verbose, Debug,
            ErrorAction, ErrorVariable, WarningAction, WarningVariable,
            OutBuffer, PipelineVariable, and OutVariable. For more information, see
            about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
    ALIASES
        None
    REMARKS
        None
    
    0 讨论(0)
  • 2020-11-28 18:20

    There is a handy tool which saves a lot of time at

    http://tools.perceptus.ca/text-wiz.php?ops=7

    You just have to feed in the table name, field names and the data - tab separated and hit Go!

    0 讨论(0)
  • 2020-11-28 18:22

    Here is a link to an Online automator to convert CSV files to SQL Insert Into statements:

    CSV-to-SQL

    0 讨论(0)
  • 2020-11-28 18:30

    Depending on the database, you can export to CSV and then use an import method.

    MySQL - http://dev.mysql.com/doc/refman/5.1/en/load-data.html

    PostgreSQL - http://www.postgresql.org/docs/8.2/static/sql-copy.html

    0 讨论(0)
  • 2020-11-28 18:31

    You can create an appropriate table through management studio interface and insert data into the table like it's shown below. It may take some time depending on the amount of data, but it is very handy.

    enter image description here

    enter image description here

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题