SQL Server:导入和导出CSV

时间:2020-12-19 08:18:38

I am working on SQL Server 2000. As you know, there is an application that's shows query results (Query Analyzer) The data is shown there, on a grid, and you can save that grid in a csv file. That's great.

我正在研究SQL Server 2000.如您所知,有一个应用程序显示查询结果(查询分析器)数据显示在网格上,您可以将该网格保存在csv文件中。那很棒。

Now, I want to INSERT those csv values into a Table. Does SQL Server provide any method?? And I mean, automatic or semi-automatic methods (like when you read an Excel from Query Analyzer). Because, for example, with a Bulk insert I can accomplish that but, it involves a lot of work.

现在,我想将这些csv值插入表中。 SQL Server是否提供任何方法?我的意思是,自动或半自动方法(例如从查询分析器中读取Excel时)。因为,例如,使用Bulk insert我可以实现这一点,但是,它涉及很多工作。

I am considering developing an application that does that (maybe in python) But, I don't want to if anything else already exists.

我正在考虑开发一个应用程序来执行该操作(可能在python中)但是,我不想,如果还有其他任何东西已经存在。

4 个解决方案

#1


0  

If you just need CSV exports/imports, I'd use BCP. It's much faster, it's easier to use for those requirements (at least in my opinion).

如果您只需要CSV导出/导入,我会使用BCP。它更快,更容易用于这些要求(至少在我看来)。

#2


3  

You can look at using DTS SSIS to do this.

您可以使用DTS SSIS来执行此操作。

DTS is what you will want to use for SQL Server 2000 (as the comments below suggest).

DTS是您希望用于SQL Server 2000的内容(如下面的评论所示)。

I believe you can also copy paste directly from a spreadsheet into a table if you're not trying to do anything too fancy. I haven't done this in a while so you'll have to double check.

我相信如果你不想做任何太花哨的事情,你也可以直接从电子表格复制粘贴到表格中。我有一段时间没有这样做,所以你必须仔细检查。

#3


1  

If you already know how to import from Excel, you can open the .CSV file(s) in Excel and save them as .xls once the conversion is done.

如果您已经知道如何从Excel导入,则可以在Excel中打开.CSV文件,并在转换完成后将其保存为.xls。

#4


1  

Why are you creating a csv file at all, why not simply insert the results of your selct statement? Assume the select you used to build the csv was :

为什么要创建一个csv文件,为什么不简单地插入selct语句的结果?假设您用于构建csv的选择是:

select a.field1, b.field2 
from anothertable a
join yetanothertable b on a.myid = b.myid

why not just do:

为什么不这样做:

insert mytable (field1, field2)
select a.field1, b.field2 
from anothertable a
join yetanothertable b on a.myid = b.myid

If you really have a csv file to import, you can do so using the import wizard if it is a one-time deal or a DTS package if it is a repeatable process you want to do on a regular schedule.

如果您确实要导入csv文件,则可以使用导入向导(如果是一次性交易)或DTS包(如果它是您希望定期执行的可重复过程)。

#1


0  

If you just need CSV exports/imports, I'd use BCP. It's much faster, it's easier to use for those requirements (at least in my opinion).

如果您只需要CSV导出/导入,我会使用BCP。它更快,更容易用于这些要求(至少在我看来)。

#2


3  

You can look at using DTS SSIS to do this.

您可以使用DTS SSIS来执行此操作。

DTS is what you will want to use for SQL Server 2000 (as the comments below suggest).

DTS是您希望用于SQL Server 2000的内容(如下面的评论所示)。

I believe you can also copy paste directly from a spreadsheet into a table if you're not trying to do anything too fancy. I haven't done this in a while so you'll have to double check.

我相信如果你不想做任何太花哨的事情,你也可以直接从电子表格复制粘贴到表格中。我有一段时间没有这样做,所以你必须仔细检查。

#3


1  

If you already know how to import from Excel, you can open the .CSV file(s) in Excel and save them as .xls once the conversion is done.

如果您已经知道如何从Excel导入,则可以在Excel中打开.CSV文件,并在转换完成后将其保存为.xls。

#4


1  

Why are you creating a csv file at all, why not simply insert the results of your selct statement? Assume the select you used to build the csv was :

为什么要创建一个csv文件,为什么不简单地插入selct语句的结果?假设您用于构建csv的选择是:

select a.field1, b.field2 
from anothertable a
join yetanothertable b on a.myid = b.myid

why not just do:

为什么不这样做:

insert mytable (field1, field2)
select a.field1, b.field2 
from anothertable a
join yetanothertable b on a.myid = b.myid

If you really have a csv file to import, you can do so using the import wizard if it is a one-time deal or a DTS package if it is a repeatable process you want to do on a regular schedule.

如果您确实要导入csv文件,则可以使用导入向导(如果是一次性交易)或DTS包(如果它是您希望定期执行的可重复过程)。