In this article we will show you, How to Export Data from SQL Server to Flat File in Informatica with example. For this example, we are going to use the below show data (Employe table)
Export Data from SQL Server to Flat File in Informatica
Before we start configuring the Informatica to Export Data from SQL Server to Text File (or Flat File). First connect to Informatica repository service by providing the Informatica Admin Console credential.
TIP : Here you have to provide the Admin Username and password that you specified while installing the Informatica Server.
Step 1: Create Source Definition
Once you connected successfully, Please navigate to Source Analyzer to define your Sources. As we said before, we are using Employe table present in the SQL Server database as our source definitions. So, go to the Source menu and select the Import from Database.. option as shown below.
Please select the ODBC connection that will connect the Informatica with the SQL Tutorial Database. In order to create new one, please refer Informatica ODBC Connection article.
From the below screenshot you can observe that, we are selecting the Employe table from our SQL Tutorial database.
This will add the table definition (Column Names, and appropriate data types) inside our work space under the Source Analyzer. Please refer Database Source to understand the creation of source definition
Step 2: Create Target Definition to move data from SQL to Text File
Please navigate to Target Designer to define the Target. In this example our task is to create a Text File target. So, go to Targets menu and select the Create option as show below.
Once you select the Create option, a new window called Create Target table will be displayed as shown below. Please provide a unique name for the target table, and select the database type as Flat File. Once you are done, Please click on the Create button to create new empty table in our PowerCenter Target Designer.
From the below screenshot you can observe that, We successfully created new empty table in our Target Designer.
In order to add new columns, we have to edit the table definition. This can be done by Right click on the table, and select the Edit.. option from the context menu. Once you select the Edit.. option, a new window called Edit tables will be opened as shown below.
By default Flat File columns will be separated by the Comma Delimiter. But, you can control the same by clicking the Advanced button
Here, you can change the Column Delimiter, and you can add Single Quoted, or double quotes each column value.
Next, go to the Columns Tab to add new columns. Please select the first button (before scissors symbol) as shown below. This will open the empty row to add Column Name, Data Type, Precision (if required), Scale (if required). If it is primary key then change the Key type to primary and check mark the Not Null option (if your column doesn’t allow null values)
From the below screenshot you can observe that, we added four columns.
You can use the Properties tab to define the Date time Format, or to change the default format. Once you added the required columns, Click OK to close the Edit tables window
Now you can that the target table had required column names.
Step 3: Create Mapping to move data from SQL to Flat File
To create a new mapping, Please navigate to Mappings menu in Menu Bar, and select the Create.. option.
This will open the Mapping Name window to write unique name for this mapping. Let me write m_export_SQL_to_text and click OK button.
TIP : Please refer Informatica Mapping article to understand the procedure to create Mapping
Drag and drop the Employe source definitions from Sources folder to the mapping designer. Once you drag the source, Power Center designer will automatically create the source qualifier for you. I suggest you to refer Source Qualifier Transformation article
Next, Drag and drop the target definition from Targets folder to the mapping designer. Next, connect the source qualifier with the target definition. Please use the Autolink.. option to connect them.
Before we close the Mapping, Let us Save, and Validate the mapping by going to Mapping Menu bar, and select the Validate option.
Step 4: Create Workflow to move data from SQL Server to Text File
After we finish creating the Mapping, we have to create the workflow for it. Power Center Workflow manager provides two approaches to create workflow.
In this example we will create the Workflow manually. To do so, Please navigate to Workflows Menu and select the Create option.
This will open Create Workflow window as shown below. Please provide the unique name (wf_export_SQL_to_text) and leave the default settings.
Once we created the workflow, our next step is to create session task for our mapping.
Step 4(a): Create Session to move data from SQL to Text File
There are two types of sessions in informatica:
For this example we created a Non-reusable Session. In order to create Non-reusable Session, Please navigate to Tasks Menu and select the Create option as shown below.
Please provide a unique name for this session. Here, we are naming it as s_export_sql_to_text
Once you click on the Create button, a new window called Mappings will be opened. Here you have to select the mapping that you want to associate with this session i.e., m_export_sql_to_text.
Please link the Start Task, and the Session Task.
Double click on the Session task will open the Edit Tasks window. Within Properties Tab, we have configure $Source connection value. This property will store the relational source information in $Source variable.
So, click on the Arrow we marked above, and select the SQL Tutorial as the source information.
You can configure the Sessions Log properties, Error properties in Config Object
Within the mappings tab, we have to configure the Source, and target Connections. First, let us configure the source connections by clicking on the SQ_Employe source present in the Sources folder.
With in the Connections, click on the Arrow button beside the Relational type, and Use Connection variable that we created in our previous step i.e., $Source
Now, we have to configure the Target Connection. So, let us configure the target connection by clicking on the Employetable present in the Targets folder.
If you requirement is Merging the data then use this Merge Type property. For now, we are leaving it to No Merge option. I suggest you to explore the remaining options.
- Append If Exists: data will be appended if the file already exits.
- Output File Directly: Informatica will use the default directory but you can change the directory by giving full path.
- Output filename: Please change the extension to txt
Next, navigate to Workflows Menu and select the Validate option to validate the Workflow. Now, Let me start the Workflow by selecting the Start Workflow option in Workflows Menu.
Once you select the Start Workflow option, Informatica PowerCenter Workflow monitor will be opened to monitor the workflow. From the below screenshot you can observe that, our workflow is executed without any errors.
Let us open the default target location of the Informatica to check whether we successfully created a text file, and transfer the data from source or not.
You can see the data inside the employee table text file.
Let me change the file location from Default Informatica destination to D folder, and also changing the name as employeetable. Next, Save and start the Workflow
Now you can see the employeetable.txt in D drive
Thank You for Visiting Our Blog