Import Excel Spreadsheet Data to an EXISTING sql table?

后端 未结 4 2323
太阳男子
太阳男子 2021-02-18 13:40

I have a table called tblAccounts whose contents will come from an excel spreadsheet.

I am using MS SQL Server 2008 (x64) on a Windows 8.1 (x64)

I tried using th

相关标签:
4条回答
  • 2021-02-18 14:14

    You can copy-paste data from en excel-sheet to an SQL-table by doing so:

    • Select the data in Excel and press Ctrl + C
    • In SQL Server Management Studio right click the table and choose Edit Top 200 Rows
    • Scroll to the bottom and select the entire empty row by clicking on the row header
    • Paste the data by pressing Ctrl + V

    Note: Often tables have a first column which is an ID-column with an auto generated/incremented ID. When you paste your data it will start inserting the leftmost selected column in Excel into the leftmost column in SSMS thus inserting data into the ID-column. To avoid that keep an empty column at the leftmost part of your selection in order to skip that column in SSMS. That will result in SSMS inserting the default data which is the auto generated ID.

    Furthermore you can skip other columns by having empty columns at the same ordinal positions in the Excel sheet selection as those columns to be skipped. That will make SSMS insert the default value (or NULL where no default value is specified).

    0 讨论(0)
  • Saudate, I ran across this looking for a different problem. You most definitely can use the Sql Server Import wizard to import data into a new table. Of course, you do not wish to leave that table in the database, so my suggesting is that you import into a new table, then script the data in query manager to insert into the existing table. You can add a line to drop the temp table created by the import wizard as the last step upon successful completion of the script.

    I believe your original issue is in fact related to Sql Server 64 bit and is due to your having a 32 bit Excel and these drivers don't play well together. I did run into a very similar issue when first using 64 bit excel.

    0 讨论(0)
  • 2021-02-18 14:31

    If you would like a software tool to do this, you might like to check out this step-by-step guide:

    "How to Validate and Import Excel spreadsheet to SQL Server database"

    http://leansoftware.net/forum/en-us/help/excel-database-tasks/worked-examples/how-to-import-excel-spreadsheet-to-sql-server-data.aspx

    0 讨论(0)
  • 2021-02-18 14:37

    You can use import data with wizard and there you can choose destination table.

    Run the wizard. In selecting source tables and views window you see two parts. Source and Destination.

    Click on the field under Destination part to open the drop down and select you destination table and edit its mappings if needed.

    EDIT

    Merely typing the name of the table does not work. It appears that the name of the table must include the schema (dbo) and possibly brackets. Note the dropdown on the right hand side of the text field.

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