Select only a set of tables

martijnbreinmartijnbrein Posts: 2
edited April 6, 2007 3:47PM in SQL Toolkit Previous Versions
Hi,

The example from Automating SQL Packager makes it possible to build a package from the whole database (tables views stored procedures users).

I only need to package a few tables from my database. How is this possible in the example?

I found this in the help file:

excludeschema
All - All database objects
Table - Tables
View - Views
StoredProcedure - Stored procedures
Default - Default.
FullTextCatalog - Full text catalogs
Function - User-defined functions
Role - Roles
Rule - Rules
User - Users
UserDefinedType - User-defined data types


To create an executable package including only tables whose names include the word "Product"

SQLPackager /database1:FirstDatabaseName /makeexe ↵
/name:PackageName /location:TargetDirectoryName /includetypes:table ↵
/include:table:Product

I hope somebody can help me

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    You'll probably want to have a look at the Packager API examples that come with the SQL Bundle. They are normally found in c:\program files\red gate\sql bundle 5\Toolkit Sample Files.

    There is a Packager example (packagedatabase.cs). With a few changes, you could use this. If you look in the SetSchemaExecutionBlock method, there is a block where you can select individual schema blocks:
    //select all the differences
    				foreach (RedGate.SQLCompare.Engine.Difference difference in differences)
    				{
    					difference.Selected=true;
    				}
    
    You could, for instance, narrow this down to only tables or only tables with a certain name:
    //select all the differences
    				foreach (RedGate.SQLCompare.Engine.Difference difference in differences)
    				{
    	if (difference.DatabaseObjectType==ObjectType.Table && difference.Name.StartsWith("[dbo].[product"))
    					difference.Selected=true;
    					else difference.Selected=false;
    				}
    
    Then, make sure that you change the mappings for the data. Right after the CreateMappings method runs, you could limit the selected tables there:
    foreach (TableMapping m in tableMappings) 
    					{
    						if (m.Obj1.Name.StartsWith("[dbo].[Product"))
    						m.Include=true;
    						else m.Include=false;
    					}
    
    Hopefully this points you in the right direction.
Sign In or Register to comment.