Import Excel Spreadsheet Data to an EXISTING sql table?

后端 未结 4 2314
太阳男子
太阳男子 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).

提交回复
热议问题