使用ssis将多个文本文件导入多个表

时间:2013-09-18 12:50:37

标签: sql sql-server

问:我在一个名为xyz的文件夹中有多个文本文件,我在sqlserver中创建了一个没有任何表的新数据库。我的问题是根据文本文件将所有这些文本文件导入新数据库使用ssis包命名的表。可以有人知道请告诉我步骤。

答:Step 1: Use foreach loop iterator to pick all files in the specific folder.

Step 2: By using script task get the column name from text file and create the tables in you database. Keep the table name in the SSIS variable.

Step 3: Choose any destination task and insert the data into the newly created tables.

我使用了foreach循环容器并选择了文本文件的路径。在第2步,我无法为列导入编写脚本。我有几个名为employee的文本文件,其中包含列id ,name和另一个部门有deptno ,location。实际上我也是sql server and ssis的初学者。任何人都知道请帮助我。

1 个答案:

答案 0 :(得分:2)

  1. 查看this link,这将向您展示如何选择文件
  2. ForEach Loop container内,您将拥有dataflow task
  3. 来源为Flat File Source,使用Flat File Connection Managerflat file connection manager expressionconnectionstring OLE DB Destination,这将是步骤1中填充的变量。
  4. 目的地将是{{1}},它将指向您的桌子。
  5. 注意:设置基本流可能更容易,FlatFile连接管理器等硬编码到其中一个文件。这将允许您使流程正常工作,然后您可以引入ForEach循环和变量/表达式以使流程灵活。

相关问题