csv逗号分隔值文件

Receiving a comma delimited file is not new technology nor is it difficult to deal with in SQL Server. As a matter of fact, it is extremely easy. There are many cases as to why you would want to do this. For example, you have an external data source that needs to be imported into your database/table. There a couple ways to do this, however the quickest and easiest way is to use the native “import” feature within SQL Server Management Studio and you can even save it to an SSIS Package at the end of the process. The end result of using this method is that the external CSV file is loaded into a SQL Server table where columns are created and rows are populated.

接收逗号分隔的文件不是新技术,也不是很难在SQL Server中处理的文件。 事实上,这非常容易。 关于为什么要执行此操作的案例很多。 例如,您有一个外部数据源,需要将其导入数据库/表中。 有两种方法可以执行此操作,但是最快,最简单的方法是使用SQL Server Management Studio中的本机“导入”功能,甚至可以在过程结束时将其保存到SSIS包中。 使用此方法的最终结果是将外部CSV文件加载到SQL Server表中,在该表中创建列并填充行。

If you are only doing a single or one off import of data import then I recommend the native Import feature within SQL Server Management Studio. If you will be doing this process more than once, then I will show you how to save this process into an SSIS package at the end so stay tuned. From SQL Server 2005-2016 the feature has not changed. For this example below, I’ve used SQL Server Express 2014 however again, it is the same across the current version as well as the past several versions. To access it, from SQL Server Management Studio, expand your server branch to your databases. Right click on your database name and open the tasks menu then select Import Data. This will bring up the SQL Server Import and Export Wizard:

如果仅一次或一次导入数据导入,则建议在SQL Server Management Studio中使用本机导入功能。 如果您将不止一次地执行此过程,那么我将向您展示如何将该过程最终保存到SSIS包中,请继续关注。 从SQL Server 2005-2016开始,功能未更改。 在下面的示例中,我再次使用了SQL Server Express 2014,但在当前版本以及过去的几个版本中,它都是相同的。 要访问它,请从SQL Server Management Studio中将服务器分支扩展到数据库。 右键单击数据库名称,然后打开任务菜单,然后选择“导入数据”。 这将显示SQL Server导入和导出向导:

The wizard opens to the splash screen. Click Next to continue:

向导将打开到初始屏幕。 单击下一步继续:

From the Data Source dropdown box, select Flat File Source then select your CSV file from the File Name Browse line that you have saved on your file system. Because we are using the flat file source, we can use a csv or txt file extension. In our example, we will use CSV.

在“数据源”下拉框中,选择“平面文件源”,然后从保存在文件系统上的“文件名浏览”行中选择CSV文件。 由于我们使用的是平面文件源,因此可以使用csv或txt文件扩展名。 在我们的示例中,我们将使用CSV。

数据源 (Data Source)

Once your file is selected, complete the rest of the form:

选择文件后,填写表格的其余部分:

Complete the Format section. If your text file contains a quote (“) around each column/row of data then make sure you add that as the Text qualifier. Header Row Delimiter defaults to {CR}{LF} which is carriage row/line feed. If you have column names in the first row(s), you may opt to skip them by selecting the number of rows to select. If you prefer to keep your column names, just let this stay with the default of 0 and make sure you check “Column names in the first data row”.

完成格式部分。 如果您的文本文件的每一列/每行数据都包含引号(“),请确保将其添加为“文本”限定符。 标题行分隔符默认为{CR} {LF},即回车行/换行符。 如果第一行中有列名,则可以选择要选择的行数来跳过它们。 如果您希望保留列名,只需将其保留为默认值0,并确保选中“第一个数据行中的列名”。

Next, select Columns from the left hand side of the Source form.

接下来,从“源”表单的左侧选择“列”。

This will give you a preview of the data to be imported. Note here you will see the column headers you opted to keep.

这将为您提供要导入数据的预览。 请注意,您将在此处看到选择保留的列标题。

Next select the “Advanced” option from the left menu. This option is important because will you be able to select your column types and column widths for each column. It is a good idea to verify that each column type and column length is appropriate for each column.

接下来,从左侧菜单中选择“高级”选项。 此选项很重要,因为您将能够为每列选择列类型和列宽。 验证每个列类型和列长是否适合每个列是一个好主意。

After you have updated each column with the appropriate column type and column width, click on the Preview option on the left menu. This will show you a preview of your data. At this time, you will also be able to go back and update column types and widths if necessary.

用适当的列类型和列宽更新每个列后,单击左侧菜单上的“预览”选项。 这将向您显示数据的预览。 此时,如果需要,您还可以返回并更新列的类型和宽度。

Click Next on the screen above. This will take you to the destination selection screen.

在上面的屏幕上单击“下一步”。 这将带您进入目的地选择屏幕。

数据库目标 (Database Destination)

From here you will need to select your destination table for the data. For this example, we are going to create a table or destination within the wizard.

在这里,您将需要选择数据的目标表。 对于此示例,我们将在向导中创建表或目标。

Change the destination to Microsoft OLE DB Provider for SQL Server. This will allow you to connect to your SQL Server.

将目标更改为SQL Server的Microsoft OLE DB提供程序。 这将允许您连接到SQL Server。

Select your Server name and Database name from the drop down boxes or type them in, then select next

从下拉框中选择服务器名称和数据库名称,或在其中键入,然后选择下一步

You will be taken to the select source and destination selection. SQL Server will automatically populate your data source that you entered at the beginning of this lesson as well as default a destination to a table named the same as your data source. If you already have a table created in your database, you may change the destination to that or just change the table name defined by SQL Server.

您将被带到选择源和目的地选择。 SQL Server将自动填充您在本课开始时输入的数据源,并默认为与数据源相同的表的目的地。 如果已经在数据库中创建了表,则可以将目标更改为该目标,或者仅更改SQL Server定义的表名。

Here you will see the source CSV file we have been working with as well as the destination table in the database. I have selected to use the default name given by SQL Server however, feel free to change the name or select a different table. Click on the Edit Mappings button, if you would like to make any changes to the destination table or edit the create table script. Here you may also enable identity insert.

在这里,您将看到我们一直在使用的源CSV文件以及数据库中的目标表。 我选择使用SQL Server提供的默认名称,但是,随时可以更改名称或选择其他表。 如果要对目标表进行任何更改或编辑创建表脚本,请单击“编辑映射”按钮。 您还可以在此处启用身份插入。

If no changes are necessary, then select OK on this screen and then select Preview on the next.

如果不需要更改,请在此屏幕上选择“确定”,然后在下一个屏幕上选择“预览”。

Preview will give you a preview of how your data will look in the table

预览将为您预览数据在表中的外观

Once data is verified, close this screen and select Next.

验证数据后,关闭此屏幕并选择“下一步”。

Now this screen is probably the most important screen in this series because it enables you to create an SSIS package after. I almost always use this option because you will not have to redo any of the steps above for subsequent runs. Also, the SSIS package can be added to a SQL agent job and scheduled. Since you save the SSIS package, you will also be able to modify the SSIS package too.

现在,此屏幕可能是该系列中最重要的屏幕,因为它使您能够在此之后创建SSIS包。 我几乎总是使用此选项,因为您不必为以后的运行重做上述任何步骤。 另外,可以将SSIS包添加到SQL代理作业中并进行计划。 由于保存了SSIS包,因此您也将能够修改SSIS包。

You have a choice to save your SSIS package directly into SQL Server or on your File System. Depending on how you are structured, neither is better than the other in my opinion, it just depends on how you want to organize it. Click next to continue. If you decide to save to the file system, you will be presented with this screen to save the file.

您可以选择将SSIS包直接保存到SQL Server或文件系统中。 根据您的结构,在我看来,哪一个都不比另一个更好,这仅取决于您要如何组织它。 单击下一步继续。 如果决定保存到文件系统,将显示此屏幕以保存文件。

Add your file name and directory location and click next. You will be presented with a confirmation screen.

添加您的文件名和目录位置,然后单击下一步。 您将看到一个确认屏幕。

Then click Finish.

然后单击完成。

If the import is successful, you should get a confirmation.

如果导入成功,您应该得到确认。

You have successfully imported a CSV file into a SQL Server table. There are no scripts involved in this process, just the native Import feature within SQL Server Management Studio. This is basic SQL Server 101 but a very important and useful tool.

您已成功将CSV文件导入到SQL Server表中。 此过程中没有脚本,只有SQL Server Management Studio中的本机导入功能。 这是基本SQL Server 101,但是是非常重要和有用的工具。

相关链接: ( Related Links: )

  • Import and Export Data with the SQL Server Import and Export Wizard 使用SQL Server导入和导出向导导入和导出数据
  • Start the SQL Server Import and Export Wizard 启动SQL Server导入和导出向导
  • Exporting SQL Server Data with SQL Server Management Studio Import and Export Wizard 使用SQL Server Management Studio导入和导出向导导出SQL Server数据

翻译自: https://www.sqlshack.com/how-to-split-a-comma-separated-value-csv-file-into-sql-server-columns/

csv逗号分隔值文件

csv逗号分隔值文件_如何将逗号分隔值(CSV)文件拆分为SQL Server列相关推荐

  1. 如何连接sql托管实例_如何使用Windows托管的文件共享来支持SQL Server容器

    如何连接sql托管实例 In a previous article, Automate Delivery of SQL Server Production Data Environments Usin ...

  2. mdf文件和ldf文件ndf是什么,怎么用?如何给SQL server添加数据文件?分离和附加数据库的操作

    目录 三种文件介绍: 附加数据库操作: 分离数据库: bak备份文件: 三种文件介绍: 在微软的SQL Server 2000 数据库有三种类型的文件: 类型 缩写 中文意思 mdf primary ...

  3. python写入csv指定单元格_使用python将值插入csv中的特定单元格

    我想知道是否有办法用python将数据插入到csv文件的特定单元格中.可以说我有变量"数据",它存储值" 300".如何将这些数据添加到csv文件的第3行第2列 ...

  4. python运行系统找不到指定文件_系统找不到指定文件_系统找不到指定的文件_python 系统找不到指定的文件 - 云+社区 - 腾讯云...

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 我正在构建一个依赖于另一个库的特定库,当我这样做时,我收到以下警告消息:&quo ...

  5. java调用帆软cpt文件_报表开发导出各种格式文件的API

    文件输出的多样性,准确性和稳定性对于我们常用的报表软件来说很重要.报表的输入是指从报表的模板文件(XML格式的)创建WorkBook对象,输出则指将报表保存为各种格式文件,比如Pdf.Excel.Wo ...

  6. nio 读取目录所有文件_在NIO.2中使用文件和目录

    nio 读取目录所有文件 在先前的文章中,我讨论了文件和目录的创建( 创建文件和目录 )以及选择( 列出和过滤目录内容 ). 采取的最后一个合乎逻辑的步骤是探索我们如何使用它们以及如何使用它们. 这是 ...

  7. java文件和xml文件_用Java分割大型XML文件

    java文件和xml文件 上周,我被要求用Java编写一些东西,该东西能够将一个30GB的XML文件拆分为可配置文件大小的较小部分. 文件的使用者将是一个中间件应用程序,该应用程序在XML的大尺寸方面 ...

  8. c fscanf 按行读取文件_每日干货丨C语言文件操作函数

    文件操作指针 FILE *fp fp变量具有指向文件内存的功能,即可以直接操作文件 注:访问文件不只可以用指针 还可以用文件流指针和文件操作符 1.1 fopen函数 对一个文件操作时一定需要先打开文 ...

  9. ncl 添加点shp文件_一:python读取shapefile文件

    使用geopandas读取shapefile格式的矢量文件 包括shapefile文件的读取.修改.保存 import geopandas as gpd # 导入包 segpath = r" ...

最新文章

  1. 7-3 逆序的三位数 (Java)
  2. c语言链表创建递归,递归创建二叉树c语言实现+详细解释
  3. 并发异步处理队列 .NET 4.5+ (改进性能计数器) 2013-11-16
  4. Android 编程下获得应用程序的签名
  5. c语言怎么独缺非空格字符,C语言-字符串(单个字符)
  6. allegro标注尺寸设置_标注新升级 | SOLIDWORKS 2020新功能揭秘
  7. Valid BFS? CodeForces - 1037D(思维 bfs)
  8. oracle在指定列后添加列,oracle添加列到指定位置
  9. win10python3.6.3安装_Win10Python3.6安装impyla
  10. 人脸对齐(二)--ASM算法
  11. Java核心技术点之反射
  12. 霍尔编码器和电机驱动L298N
  13. Mikrotik ROS软路由配置PCC负载均衡实现双宽带叠加
  14. 2022产业区块链数智经济发展论坛圆满举行
  15. windows11便签在哪里,win11怎么新建便签
  16. 【图像处理算法常用数据集】整理第一弹
  17. 智慧教室解决方案-最新全套文件
  18. 暴露在公网环境下主机的安全防护
  19. 智原深耕网通应用 布建完整ASIC解决方案
  20. ecshop数据字典

热门文章

  1. Web基础知识(一)
  2. Labelary Online ZPL Viewer
  3. easyUi easyui-textbox 多行换行失效问题
  4. 【无标题】通过邮箱注册账号,邮箱返回注册信息
  5. Jena Ontology API
  6. 简单的提示词操作融合微调 AI 图像
  7. TF 菜鸡入门(一)
  8. ironpython教程_初步了解IronPython
  9. jfreechart java配置_JFREECHART环境安装配置
  10. 这样算懒惰的程序员吗?