Attribute VB_Name = "Module1" ' *************************************************************************** ' Copyright (C) 1991-2003 SQLDev.Net ' ' $BeginHeader$ ' ' @file@: ScriptViewsDependent.bas ' @author@: Gert E.R. Drapers (GertD@SQLDev.Net) ' @description@: Example: script views using SQL-DMO Transfer object ' @remarks@: ' @created@: 2003-03-02 ' @lastsaved@: 2003-03-02 ' ' update history: ' @version@ @initials@ @updatedate@ @release@ @description@ ' 00000 GED 2003-03-02 v1.0.0.0 created ' ' @EndHeader@ ' *************************************************************************** Option Explicit Public Sub main() On Error GoTo errHandler Dim oSQLServer As SQLDMO.SQLServer2 Set oSQLServer = New SQLDMO.SQLServer2 oSQLServer.LoginSecure = True oSQLServer.Connect "(local)\dev" Dim oDatabase As SQLDMO.Database2 Set oDatabase = oSQLServer.Databases("pubs") Dim oTransfer As SQLDMO.Transfer2 Set oTransfer = New SQLDMO.Transfer2 With oTransfer .CopyAllObjects = False ' implied by CopyAllObjects = False .CopyAllDefaults = False .CopyAllFunctions = False .CopyAllRules = False .CopyAllStoredProcedures = False .CopyAllTables = False .CopyAllTriggers = False .CopyAllUserDefinedDatatypes = False .CopyAllViews = False .CopyData = SQLDMOCopyData_False ' SQLDMOCopyData_Append or SQLDMOCopyData_Replace .CopySchema = True .IncludeDB = False .IncludeDependencies = False .IncludeUsers = False .IncludeGroups = False .IncludeLogins = False .DropDestObjectsFirst = False .ScriptType = SQLDMOScript_Default + _ SQLDMOScript_Drops + _ SQLDMOScript_NoDRI + _ SQLDMOScript_Bindings + _ SQLDMOScript_OwnerQualify .Script2Type = SQLDMOScript2_Default Dim oView As SQLDMO.View2 For Each oView In oDatabase.Views If oView.SystemObject = False Then .AddObjectByName oView.Name, SQLDMOObj_View, oView.Owner End If Next End With ' single file oDatabase.ScriptTransfer oTransfer, SQLDMOXfrFile_SingleFile, "c:\temp\views.sql" ' directory ' oDatabase.ScriptTransfer oTransfer, SQLDMOXfrFile_SingleFilePerObject, "c:\temp" Set oTransfer = Nothing Set oDatabase = Nothing oSQLServer.DisConnect Set oSQLServer = Nothing Exit Sub errHandler: Debug.Print "Error " & Err.Number & " " & Err.Description End Sub