9

我有一个非常简单的 excel 表:

在此处输入图像描述

我想将此数据放入 SQL Server 中的表中。我还想添加一个包含日期的字段。

做这个的最好方式是什么?

4

6 回答 6

10

Create a table in SQL server with the same number of fields that you have in the spreadsheet.

In SQL Server Management Studio Object Explorer you can right click the table you created and select "Edit top 200 rows". Highlight the data you want to copy in Excel and right click -> copy. Right click the space to the left of the first row in the SSMS edit tabe widow and paste.

After the import check the SQL table to make sure it has the same amount of rows as the spreadsheet.

You can add the date column to the SQL table after you do the data import. Or add it in the spreadsheet before you do the import.

于 2013-04-17T14:02:09.543 回答
6

您可以先在 SQL Server 中使用添加的字段创建表,然后使用 Mangement Studio 中的导入向导导入 excel 文件。或者您在导入任务期间创建表,稍后添加新字段。

于 2013-04-17T13:23:42.637 回答
2

选项1:

读取 IDataReader 中的数据,然后调用存储过程插入数据。

http://granadacoder.wordpress.com/2009/01/27/bulk-insert-example-using-an-idatareader-to-strong-dataset-to-sql-server-xml/

当我有~~很多~~要导入的行并且我想在数据库之外验证它们时,我会使用上述方法。

选项 2:

http://support.microsoft.com/kb/321686

或搜索:

Select  FROM OPENDATASOURCE Excel

选项 N:

还有其他选择。

这取决于你喜欢什么,你想投入多少时间,是“一次性”还是你必须每天为 333 个文件做。

于 2013-04-17T13:21:55.910 回答
1

我的解决方案是将 .xlsx 转换为 .csv,然后使用此站点将 .csv 转换为 .sql。然后我在 sql server 中运行 sql 文件并生成我的表。

于 2017-10-27T18:26:55.323 回答
0

It can be also be done by creating a batch file.

For this you already need to have a table created on server with the same data structure as you have in excel.

Now using BCP you can import that data from the excel file and insert it into sql table.

BCP utility function

sqlcmd -S IP -d databasename -U username -P passwd -Q "SQL query mostly it should be truncate query to truncate the created table"
bcp databasename.dbo.tablename in "Excel file path from where you need to input the data" -c -t, -S Server_IP -U Username -P passwd -b provide batch size

You can refer to the link below for more options on the bcp utility:

https://msdn.microsoft.com/en-IN/library/ms162802.aspx

于 2015-05-28T10:38:23.570 回答
-2

打开您的 SQL Server 界面软件,将日期字段添加到表中。

转到excel,添加日期列,复制excel数据。

转到您的 SQL 服务器界面软件并使用该功能从剪贴板导入数据。(具有此功能的 SQL 服务器接口软件例如 Database4.net,但如果您有另一个具有该功能的软件包,请使用它。)


或者使用带有 DOA 或 ADO 的 VBA 与 SQL 服务器数据库交互,并使用 SQL 语句添加字段并将数据复制到表中

于 2013-04-17T13:20:16.087 回答