Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

The Basics of Biml the Execute SQL Task

$
0
0
A couple years ago, I wrote a series of guest posts about the Basics of SSIS for my friend Pinal Dave’s [ Blog | @pinaldave ] popular blog, SQL Authority . In that series, I pointed out that I use only a handful of SSIS Control Flow tasks when designing SSIS packages. You can find the series here:

Execute SQL Task

Data Flow Task

Script Task

Execute Package Task

File System Task ( Part 1 , Part 2 )

Execute Process Task

In this post, I’m going to demonstrate and discuss building the Execute SQL Task using Biml.


The Basics of Biml   the Execute SQL Task

“So how does one build an Execute SQL Task using Biml, Andy?” I’m glad you asked. First you have to build an SSIS package in Biml. But before you build an SSIS package in Biml, you need to populate the Biml Relational Hierarchy. To play along at home grab the 14-day free trial of Mist here and download the World Wide Importers sample database here . Then go learn how to populate the Biml Relational Hierarchy by reading this post: The Basics of Biml Populating the Biml Relational Hierarchy . You’ll be glad you did.

The Prerequisites

I’m going to continue building out the demo Mist project named BimlBasics the one I started in The Basics of Biml Populating the Biml Relational Hierarchy . (I told you you’d be glad you read that post!)

Create an SSIS Package

You can create an SSIS package using the Mist GUI. But for this exercise, let’s build one from the ground up using Biml. In Logical View, right-click Library―>Utilities and then click Add BimlScript:


The Basics of Biml   the Execute SQL Task

I named my BimlScript file “TruncateAndLoad_People.biml”:


The Basics of Biml   the Execute SQL Task

If I double-click the file in Logical View, the BimlScript Input Editor displays my file contents:


The Basics of Biml   the Execute SQL Task

If you position your cursor at the end of line 1 and press the Enter key a new, properly-indented line begins. Type “<” to begin adding Biml to your file. Note the IntelliSense provides a list of options available at this level of the Biml object model:


The Basics of Biml   the Execute SQL Task

Double-click Packages to begin creating a Packages collection:


The Basics of Biml   the Execute SQL Task

Type the “close tag” symbol “>” and Biml automagically generates the close tag: </Packages>:


The Basics of Biml   the Execute SQL Task

Position your cursor between the opening and closing Packages tags and press the Enter key. A new properly-indented line appears:


The Basics of Biml   the Execute SQL Task

Type the “open tag” symbol (“<”) and IntelliSense provides a list of valid Biml objects. Type of click Package to proceed:


The Basics of Biml   the Execute SQL Task

Type a space at the end of the word “Package” followed by the letter “N.” Note the Name attribute is highlighted by IntelliSense:


The Basics of Biml   the Execute SQL Task

Enter “Package1” as the Name attribute value:


The Basics of Biml   the Execute SQL Task

Close the Package tag:


The Basics of Biml   the Execute SQL Task

Press Enter to start a new, properly-indented line. Use IntelliSense (or type) to add a “<Tasks>” tag:


The Basics of Biml   the Execute SQL Task

Inside the Tasks tag, add an “<ExecuteSQL>” tag:


The Basics of Biml   the Execute SQL Task

Add the ConnectionName attribute:


The Basics of Biml   the Execute SQL Task

Note IntelliSense supplies valid values WorldWideImporters, in this case to the attribute:


The Basics of Biml   the Execute SQL Task

Supply a Name attribute for the Execute SQL Task and close the tag:


The Basics of Biml   the Execute SQL Task

Inside the ExecuteSQL tag, next a DirectInput tag:


The Basics of Biml   the Execute SQL Task

In Logical View, right-click the Application.People table, hover over Copy SQL Script, and then click Select SQL:


The Basics of Biml   the Execute SQL Task

Position your cursor between the DirectInput tags and paste the clipboard contents:


The Basics of Biml   the Execute SQL Task

Look at all that well-formatted T-SQL! How neat is that ?


The Basics of Biml   the Execute SQL Task

We’ve been ignoring this message at the top of the BimlScript Input Editor for a while now:


The Basics of Biml   the Execute SQL Task

Click it.

Observe the Preview Expanded BimlScript window:


The Basics of Biml   the Execute SQL Task

That right there is your Package1.dtsx Biml.

Next Steps

You do not yet have an SSIS package. You have the Biml template of a package. I can hear you thinking, “So how does this become an SSIS package, Andy?” I’m glad you asked!

We now need to execute the BimlScript and then build the output.

Execute the BimlScript

First, we execute the BimlScript file. In Logical View, right-click the TruncateAndLoad_People.biml file (found in Library―>Utilities) and click Execute BimlScript:


The Basics of Biml   the Execute SQL Task

The Biml template of an SSIS package has now been executed. It generated the Biml version of an SSIS package. In the image below, I positioned the Logical View and Project View side-by-side for comparison:


The Basics of Biml   the Execute SQL Task

We now have a Biml representation of the SSIS package named Package1.dtsx.

Build the Package

To generate the actual SSIS package, right-click Package1 (found in Logical View―>Integration Services―>Packages) and then click Build:


The Basics of Biml   the Execute SQL Task

The Output window displays the results of the Build operation:


The Basics of Biml   the Execute SQL Task

An SSIS project is generated in the output folder of the BimlBasics Mist project folder:


The Basics of Biml   the Execute SQL Task

The package was generated just as we specified:


The Basics of Biml   the Execute SQL Task

And it runs!


The Basics of Biml   the Execute SQL Task

Conclusion

In this post, I discussed and demonstrated how to configure an SSIS package that contains an Execute SQL Task, one of the handful of tasks I use when designing SSIS packages.

:{>

Related Training: IESSIS2: Immersion Event on Advanced SQL Server Integration Services


Viewing all articles
Browse latest Browse all 3160

Trending Articles