SMO Tables DBCC Package Sample

The SMOTablesDBCC sample package illustrates how to enumerate the user tables in the
AdventureWorks database by using the Foreach SMO enumerator in a Foreach Loop container. First, a Script task retrieves the schema and table names and puts them into two variables. Next, an Execute SQL task executes a DBCC CHECKCONSTRAINTS command using
the two variables.

Note:

To allow the package to run in a 64-bit environment the PreCompile property of the Script task is set to
True. If you want the step through the script by using debugging tools, you should set the property to
False.

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples.

Requirements

Running this sample package requires the following:

Locate the following files and copy them under %windir%\Microsoft.NET\Framework\v2.0.xxxxx (where xxxxx is the highest version of your .NET Framework):

The sample package and data files that it uses must be installed on your local hard disk drive.

You must have installed and have administrative permissions on the AdventureWorks database.

If you intend only to run the sample package from the command line, you must install SQL Server 2005 Integration Services (SSIS).

If you intend to open the package in SSIS Designer and run the sample package, you must install Business Intelligence Development Studio. For more information about how to install samples, see the topic, "Installing Sample Integration Services Packages",
in SQL Server 2005 Books Online. To obtain the latest version of the samples, including new samples released since the original release of SQL Server 2005, see
SQL Server 2005 Samples and Sample Databases (April 2006).

Location of the Sample Package

If the samples were installed to the default installation location, the SMOTablesDBCC sample package is located in the following folder:
C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Package Samples\SmoTablesDBCC\SmoTablesDBCC\
The following files are required to run this sample package.

File

Description

SmoTablesDBCC.dtsx

The sample package.

Running the Sample

The package can be run from the command line by using the dtexec utility, or can be run in Business Intelligence Development Studio.

To run the package by using dtexec

Open a Command Prompt window.

Change the directory to C:\Program Files\Microsoft SQL Server\90\DTS\Binn, the location of
dtexec.

Press Enter.For more information about how to run the package by using the
dtexec utility, see the topic, "dtexec Utility", in SQL Server 2005 Books Online.

To run the package in Business Intelligence Development Studio

Open Business Intelligence Development Studio.

On the File menu, point to Open, and click Project/Solution.

Locate the SmoTablesDBCC folder, and then double-click the file named SmoTablesDBCC.sln.

In Solution Explorer, right-click SmoTablesDBCC.dtsx in the SSIS Packages folder, and then click
Execute Package.

Components in Sample

The following table lists the Integration Services tasks, containers, and connection managers that are used in the sample.

Element

Purpose

Foreach Loop

The Foreach Loop container, Foreach Loop Container, uses the Foreach SMO enumerator to iterate through the tables in the
AdventureWorks database. The Foreach Loop container includes a Script and an Execute SQL task.

Script task

The Script task updates the values of variables with the names of the schema and table on each iteration of the loop.

Execute SQL task

The Execute SQL task, DBCC CHECK CONSTRAINTS, runs a DBCC command on each iteration of the loop.

OLE DB connection manager

The OLE DB connection manager, (local).AdventureWorks, connects to the
AdventureWorks database on the local server.