Wednesday, March 28, 2012

How to Transfer View only?

Hi,
I'm using MS SQL Server 2000
I have 2 Northwind databases on the same server (local)
NwindA and NwindB
In NwindA I have vNewView
How do I transfer this vNewView from A to B (just the view not the data)
( I have hundreds of view that I need to transfer)
Thanks,
Oded DrorOded,shalom
I'd prefer doing such tasks with SQL DMO objects. Also , you can generate
script of all objects by using EM (right click on the database then
'Generate SQL Script')
Look at this example scripting all views into the file.
Sub ScriptDB(strLogin As String, strPwd As String, _
strDataBase As String, StrFilePath As String)
Dim sql As Object
Dim db As Object
Dim objTrigger As Object
Dim intOptions As Long
Dim genObj
Set sql = CreateObject("SQLDMO.SQLServer")
Set db = CreateObject("SQLDMO.Database")
Const sDrops As Integer = 1
Const sIncludeHeaders As Long = 131072
Const sDefault As Integer = 4
Const sAppendToFile As Integer = 256
Const sBindings As Integer = 128
' Set scripting options. Because you need to specify multiple behaviors
' for the ScriptType argument, you use "Or" to combine these.
intOptions = sDrops Or sIncludeHeaders Or _
sDefault Or sAppendToFile Or sBindings
' Connect to local server
sql.Connect "(local)", strLogin, strPwd
Set db = sql.Databases(strDataBase, "dbo")
' Script Views, ignoring system views and informational schemas
For Each genObj In db.Views
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
MsgBox "Finished generating SQL scripts."
End Sub
Save the module as MyModule.
To call the procedure, open the Immediate window, type the following line,
and then press ENTER:Call
ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
"Oded Dror" <odeddror@.cox.net> wrote in message
news:O6lABUGAGHA.208@.tk2msftngp13.phx.gbl...
> Hi,
> I'm using MS SQL Server 2000
> I have 2 Northwind databases on the same server (local)
> NwindA and NwindB
> In NwindA I have vNewView
> How do I transfer this vNewView from A to B (just the view not the data)
> ( I have hundreds of view that I need to transfer)
> Thanks,
> Oded Dror
>|||In EM, right-click your source db and choose All Tasks | Export Data. In th
e
wizard, fill out the connection and database names.
Choose "Copy objects and data between..."
Deselect "Include all dependent objects"
Deselect "Copy Data"
Deselect "Copy all objects."
Click "Select Objects".
Find and select the views you want.
Deselect "Use default options"
Click "Options" and verify the settings such as copying the database users,
etc.
Finish the wizard with run immediate or schedule later.
Hope that helps,
Joe
"Oded Dror" wrote:

> Hi,
> I'm using MS SQL Server 2000
> I have 2 Northwind databases on the same server (local)
> NwindA and NwindB
> In NwindA I have vNewView
> How do I transfer this vNewView from A to B (just the view not the data)
> ( I have hundreds of view that I need to transfer)
> Thanks,
> Oded Dror
>
>sql

No comments:

Post a Comment