Wednesday, February 15, 2012

Export script data from sql server - suggestions for this case

Hello Guys,
I would like to export my database into a file in order to be used in
another server that I do not know? So, I would to be able to exprot
all the table structure, stored procedures and data (insert into).
How can I do it?
InaPerhaps you just need a database backup.
Ben Nevarez, MCDBA, OCP
Database Administrator
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Ben
She wanted as I understood her only table's structure without any data
So , he may want to use SQLDMO objects to script out or Generate Script
Option in the EM
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")
Set objTrigger = CreateObject("SQLDMO.Trigger")
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 User Defined Data Types
For Each genObj In db.UserDefinedDatatypes
genObj.Script intOptions, StrFilePath
Next
' Script Tables and Triggers, ignoring system
' tables and system generated triggers
For Each genObj In db.Tables
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
For Each objTrigger In genObj.Triggers
If objTrigger.SystemObject = False Then
objTrigger.Script intOptions, StrFilePath
End If
Next
End If
Next
' Script Rules
For Each genObj In db.Rules
genObj.Script intOptions, StrFilePath
Next
' Script Defaults
For Each genObj In db.Defaults
genObj.Script intOptions, StrFilePath
Next
' Script Sprocs, ignoring system sprocs
For Each genObj In db.StoredProcedures
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
' 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.
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
"Ben Nevarez" <bnevarez@.sjm.com> wrote in message
news:03E4FC21-234C-42DF-BF2D-649922C22CE0@.microsoft.com...[vbcol=seagreen]
> Perhaps you just need a database backup.
> Ben Nevarez, MCDBA, OCP
> Database Administrator
>
> "ina" wrote:
>|||Use www.sqlscripter.com to generate the data scripts for tables.
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Use www.sqlscripter.com to generate the data scripts for tables.
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>

No comments:

Post a Comment