简体   繁体   English

SQL Server:导入和导出CSV

[英]SQL Server: Import and Export CSV

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. 我正在使用SQL Server2000。您知道,有一个显示查询结果的应用程序(查询分析器),该数据显示在网格上,您可以将该网格保存到csv文件中。 That's great. 那很棒。

Now, I want to INSERT those csv values into a Table. 现在,我想将这些csv值插入表中。 Does SQL Server provide any method?? SQL Server是否提供任何方法? And I mean, automatic or semi-automatic methods (like when you read an Excel from Query Analyzer). 我的意思是自动或半自动方法(例如当您从查询分析器中读取Excel时)。 Because, for example, with a Bulk insert I can accomplish that but, it involves a lot of work. 因为,例如,使用大容量插件可以完成此任务,但是它涉及许多工作。

I am considering developing an application that does that (maybe in python) But, I don't want to if anything else already exists. 我正在考虑开发一个可以做到这一点的应用程序(也许在python中),但是,我不想要任何其他已有的东西。

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. 我已经有一段时间没有这样做了,因此您必须仔细检查。

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

Why are you creating a csv file at all, why not simply insert the results of your selct statement? 为什么要创建一个csv文件,为什么不简单地插入selct语句的结果呢? Assume the select you used to build the csv was : 假设您用来构建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包(如果它是可重复的过程)。

If you just need CSV exports/imports, I'd use BCP. 如果您只需要CSV导出/导入,则可以使用BCP。 It's much faster, it's easier to use for those requirements (at least in my opinion). 它更快,更容易满足这些要求(至少在我看来)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM