Readme_SMO Tables DBCC Package Sample
This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.
This sample works with the SQL Server 2005 version of the AdventureWorks
OLTP database. To install this database, see Sample Databases for Microsoft SQL Server 2008
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.
For more information, see the topics, "Foreach Loop Container," "Script Task," and "Execute SQL Task," in SQL Server Books Online.
| Important: |
| 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. |
Running this sample package requires the following:
- Ensure that the following files are installed in the global assembly cache:
- %ProgramFiles%\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll
- %ProgramFiles%\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SmoEnum.dll
- %ProgramFiles%\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll
- 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 OLTP database.
- If you intend only to run the sample package from the command line, you must install Integration Services.
- 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 Books Online.
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\100\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 (dtexec.exe), 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\100\DTS\Binn, the location of dtexec.
- Type the following command: * dtexec /f "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\SmoTablesDBCC\SmoTablesDBCC\SmoTablesDBCC.dtsx" *
- Press Enter.For more information about how to run the package by using the dtexec utility, see the topic, "dtexec Utility", in SQL Server 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. |
After you execute the package, you should see output similar to the following output.Sample Output: Started: 10:41:04 AM Progress: 2005-03-15 10:41:06.04 Source: DBCC CHECK CONSTRAINTS Executing query "DBCC CHECKCONSTRAINTS('[dbo].[AWBuildVersion]') WI".: 100% complete End Progress Progress: 2005-03-15 10:41:06.07 Source: DBCC CHECK CONSTRAINTS Executing query "DBCC CHECKCONSTRAINTS('[dbo].[DatabaseLog]') WITH ".: 100% complete End Progress … Progress: 2005-03-15 10:38:16.81 Source: DBCC CHECK CONSTRAINTS Executing query "DBCC CHECKCONSTRAINTS('[Sales].[Store]') WITH ALL_".: 100% complete End Progress Progress: 2005-03-15 10:38:16.91 Source: DBCC CHECK CONSTRAINTS Executing query "DBCC CHECKCONSTRAINTS('[Sales].[StoreContact]') WI".: 100% complete End Progress DTExec: The package execution returned DTSER_SUCCESS (0). Started: 10:37:25 AM Finished: 10:38:17 AM Elapsed: 51.687 seconds
© 2008 Microsoft Corporation. All rights reserved.