Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Thursday, March 29, 2012

Exporting result set to a file

Hi All

I have written a sp and I would like to export he result set to a file.

Is there a bit of script I can add to do this for me?

Many Thanks

Rich

Code Snippet

exec master..xp_cmdshell 'bcp "select * from <mytable>" queryout c:\<myFile.txt> -S<Servername> -U<myUserId> -P<myPassword>'

replacing all the <...> fields with your values

|||Thankssql

Tuesday, March 27, 2012

Exporting From SQL Server To MSACCESS

Hi,

I Need to make a script or task that programmatically export data from SQL Server to Access File , and how to call the script from the .NET?

Create SSIS package using Import/Export Wizard, you can then run this package from any .NET application either by running DTEXEC or using SSIS object model - see SQL Books Online for sample syntax of both.

Wednesday, March 21, 2012

Exported Stored procedures

Hello and thanks to all of the helpers!
Especially for Linchi Shea for the Perl script.
When I compare the sql script created by the perl script (after little
modification on my side) with the one created by the MS GUI tool for
creating SQL scripts, I get the stored procedues on different order. When
running the script from SQL Query Analyzer, it displays errors (warnings?):
"Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'GUIRemoveEntity'. The stored procedure will
still be created."
I understand that the order of them DOES matter, but, if at the end of the
process, all of the SPs are loaded, will everything work?
Thanks!
RoeeIf the script is atomic (e.g. drops and re-creates the stored procedures),
running the script a second time should solve the problem.
sysdepends is generally unreliable anyway, and I typically ignore this
message unless I heavily rely on the feature and religiously make sure it is
correct.
A
"Roee Friedman" <necnecnecnec@.hotmail.com> wrote in message
news:bo5mfh$182orj$1@.ID-200860.news.uni-berlin.de...
> Hello and thanks to all of the helpers!
> Especially for Linchi Shea for the Perl script.
> When I compare the sql script created by the perl script (after little
> modification on my side) with the one created by the MS GUI tool for
> creating SQL scripts, I get the stored procedues on different order. When
> running the script from SQL Query Analyzer, it displays errors
(warnings?):
> "Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'GUIRemoveEntity'. The stored procedure will
> still be created."
> I understand that the order of them DOES matter, but, if at the end of the
> process, all of the SPs are loaded, will everything work?
> Thanks!
> Roee
>|||Just a word of caution. if you run the script twice with
DROP PROC placed immediately before its respective CREATE
PROC, you won't see the error message. But it doesn't
solve the problem of dependency.
The best you can do with sysdepends is not to use it.
The only way to be sure of the dependency is to scan the
TSQL code and sort the depenency yourself. If you see
anybody claiming that his tool correctly handles the
procedure dependency, ask how he determines the
dependency. If it doesn't parse the code, don't believe it.
In addition, if someone claims that he has a pure TSQL
script that can sort the SP dependency correctly, don't
believe it either.
Rosee, I do have a Perl script that scan the SP code and
sort them by their dependency. Drop me an email if you are
interested.
Linchi
>--Original Message--
>If the script is atomic (e.g. drops and re-creates the
stored procedures),
>running the script a second time should solve the problem.
>sysdepends is generally unreliable anyway, and I
typically ignore this
>message unless I heavily rely on the feature and
religiously make sure it is
>correct.
>A
>
>"Roee Friedman" <necnecnecnec@.hotmail.com> wrote in
message
>news:bo5mfh$182orj$1@.ID-200860.news.uni-berlin.de...
>> Hello and thanks to all of the helpers!
>> Especially for Linchi Shea for the Perl script.
>> When I compare the sql script created by the perl
script (after little
>> modification on my side) with the one created by the MS
GUI tool for
>> creating SQL scripts, I get the stored procedues on
different order. When
>> running the script from SQL Query Analyzer, it displays
errors
>(warnings?):
>> "Cannot add rows to sysdepends for the current stored
procedure because it
>> depends on the missing object 'GUIRemoveEntity'. The
stored procedure will
>> still be created."
>> I understand that the order of them DOES matter, but,
if at the end of the
>> process, all of the SPs are loaded, will everything
work?
>> Thanks!
>> Roee
>>
>
>.
>|||> The only way to be sure of the dependency is to scan the
> TSQL code and sort the depenency yourself.
Agreed.
> Rosee, I do have a Perl script that scan the SP code and
> sort them by their dependency.
I'm sure this could be done in T-SQL as well... maybe an interesting
exercise if I get bored. :-)|||Aaron;
Do you want to bet two beers at PASS2003 (if you are
going) that if a robust SP dependency sort program is done
in TSQL, it would be so ugly that it's practically
undoable? Ugliness is of course a matter of opinion and
lies the eyes of the the beholder :-)
I have no doubt you can do it in TSQL or any other
language that supports varibles, some string functions,
and the basic set of control flow constructs.
One of the major problems of doing this in TSQL is that
you need true recursion, which you can simulate with TSQL,
but rather unsightly. By 'robust', I mean it has to deal
with all the nuances.
Linchi
>--Original Message--
>> The only way to be sure of the dependency is to scan the
>> TSQL code and sort the depenency yourself.
>Agreed.
>> Rosee, I do have a Perl script that scan the SP code and
>> sort them by their dependency.
>I'm sure this could be done in T-SQL as well... maybe an
interesting
>exercise if I get bored. :-)
>
>.
>sql

Sunday, February 19, 2012

Export the schema and data

How do I export the database schema along with data, SP, Views..etc into a
script file ?Use DTS (for SQL 2000) or SSIS (for SQL 2005)
--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Alan T" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:u1Z8ZY$qGHA.1368@.TK2MSFTNGP05.phx.gbl...
> How do I export the database schema along with data, SP, Views..etc into a
> script file ?
>|||Is DTS only apply to a single database object?
I want to export the whole database into a single script file.
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uRajXfBrGHA.2180@.TK2MSFTNGP05.phx.gbl...
> Use DTS (for SQL 2000) or SSIS (for SQL 2005)
> --
> Arnie Rowland
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "Alan T" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
> news:u1Z8ZY$qGHA.1368@.TK2MSFTNGP05.phx.gbl...
>> How do I export the database schema along with data, SP, Views..etc into
>> a script file ?
>|||In Enterprise Manager, [Right Click] on the database, and select [All Tasks]
and then [Generate SQL Script].
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Alan T" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:OPlM5fV4GHA.3452@.TK2MSFTNGP05.phx.gbl...
> Is DTS only apply to a single database object?
> I want to export the whole database into a single script file.
> "Arnie Rowland" <arnie@.1568.com> wrote in message
> news:uRajXfBrGHA.2180@.TK2MSFTNGP05.phx.gbl...
>> Use DTS (for SQL 2000) or SSIS (for SQL 2005)
>> --
>> Arnie Rowland
>> Most good judgment comes from experience.
>> Most experience comes from bad judgment.
>> - Anonymous
>>
>> "Alan T" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
>> news:u1Z8ZY$qGHA.1368@.TK2MSFTNGP05.phx.gbl...
>> How do I export the database schema along with data, SP, Views..etc into
>> a script file ?
>>
>|||Arnie Rowland wrote:
> In Enterprise Manager, [Right Click] on the database, and select [All Tasks]
> and then [Generate SQL Script].
>
That won't include the data, however. By far, the easiest way to "get"
the schema AND data together is via a backup/restore. If you really
want a script, i.e. a bunch of INSERT statements, to reproduce a table,
have a look here:
http://www.realsqlguy.com/serendipity/archives/15-Table-For-Two.html
This is a rough script that needs cleaned up a bit, but it's usable as-is.
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Friday, February 17, 2012

Export table content to sql script

Is it possible in SQL express and SQL server mangement studio express to export table content to sql script, like form table

column1 column2
1 2 2
2 3 34
3 4 234

we get script

INSERT INTO [database].[dbo].[table] ([column1] ,[column2]) VALUES (2,2)

INSERT INTO [database].[dbo].[table] ([column1] ,[column2]) VALUES (3,34)

INSERT INTO [database].[dbo].[table] ([column1] ,[column2]) VALUES (4,234)

?

If it is not possible in express editions, is it at least available in developer editions?

Have a look here: http://vyaskn.tripod.com/code.htm#inserts

HTH, Jens SUessmeyer.

http://www.sqlserver2005.de

Export Stored Procedure SQL Script

We usually keep an "installation " table , when we save out stored
procedures they are ordered by the stated execution order. (customised
script)
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:eXOzROPmGHA.4164@.TK2MSFTNGP03.phx.gbl...
> I just use the 'Generate SQL Script' from EM to export stored procedure.
> How do I export the Stored Procedure SQL Script in to a file so in an
order
> so that they can be created successfully ?
> I got an error when execute the scripts:
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp1'. The stored procedure will still be
> created.
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp2'. The stored procedure will still be
> created.
> ...............
> ...............
> How do I get around that ?
>I just use the 'Generate SQL Script' from EM to export stored procedure.
How do I export the Stored Procedure SQL Script in to a file so in an order
so that they can be created successfully ?
I got an error when execute the scripts:
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'sp1'. The stored procedure will still be
created.
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'sp2'. The stored procedure will still be
created.
...............
...............
How do I get around that ?|||We usually keep an "installation " table , when we save out stored
procedures they are ordered by the stated execution order. (customised
script)
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:eXOzROPmGHA.4164@.TK2MSFTNGP03.phx.gbl...
> I just use the 'Generate SQL Script' from EM to export stored procedure.
> How do I export the Stored Procedure SQL Script in to a file so in an
order
> so that they can be created successfully ?
> I got an error when execute the scripts:
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp1'. The stored procedure will still be
> created.
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp2'. The stored procedure will still be
> created.
> ...............
> ...............
> How do I get around that ?
>

Export Stored Procedure SQL Script

I just use the 'Generate SQL Script' from EM to export stored procedure.
How do I export the Stored Procedure SQL Script in to a file so in an order
so that they can be created successfully ?
I got an error when execute the scripts:
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'sp1'. The stored procedure will still be
created.
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'sp2'. The stored procedure will still be
created.
...............
...............
How do I get around that ?We usually keep an "installation " table , when we save out stored
procedures they are ordered by the stated execution order. (customised
script)
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:eXOzROPmGHA.4164@.TK2MSFTNGP03.phx.gbl...
> I just use the 'Generate SQL Script' from EM to export stored procedure.
> How do I export the Stored Procedure SQL Script in to a file so in an
order
> so that they can be created successfully ?
> I got an error when execute the scripts:
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp1'. The stored procedure will still be
> created.
> Cannot add rows to sysdepends for the current stored procedure because it
> depends on the missing object 'sp2'. The stored procedure will still be
> created.
> ...............
> ...............
> How do I get around that ?
>|||Thanks.
I reordered some of the sp based on the depenancies.
However, I still got error in one of the sp in which a recursion occurrs:
CREATE PROCEDURE dbo.recur_sp
@.parent_id int
as
........
if exists(select 1 from category where parent_id=@.id)
exec recur_sp @.id
select @.row = @.row + 1
end
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'recur_sp'. The stored procedure will still be
created.
"Jack Vamvas" <DEL_TO_REPLYtechsupport@.ciquery.com> wrote in message
news:ELCdnem5EM1sDgLZRVnyvQ@.bt.com...
> We usually keep an "installation " table , when we save out stored
> procedures they are ordered by the stated execution order. (customised
> script)
>
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> ___________________________________
>
> "Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
> news:eXOzROPmGHA.4164@.TK2MSFTNGP03.phx.gbl...
>> I just use the 'Generate SQL Script' from EM to export stored procedure.
>> How do I export the Stored Procedure SQL Script in to a file so in an
> order
>> so that they can be created successfully ?
>> I got an error when execute the scripts:
>> Cannot add rows to sysdepends for the current stored procedure because it
>> depends on the missing object 'sp1'. The stored procedure will still be
>> created.
>> Cannot add rows to sysdepends for the current stored procedure because it
>> depends on the missing object 'sp2'. The stored procedure will still be
>> created.
>> ...............
>> ...............
>> How do I get around that ?
>>
>|||That "error" is normal for recursive procs. It's just a warning and can be
safely ignored.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
news:eSD7sVYmGHA.4816@.TK2MSFTNGP03.phx.gbl...
Thanks.
I reordered some of the sp based on the depenancies.
However, I still got error in one of the sp in which a recursion occurrs:
CREATE PROCEDURE dbo.recur_sp
@.parent_id int
as
........
if exists(select 1 from category where parent_id=@.id)
exec recur_sp @.id
select @.row = @.row + 1
end
Cannot add rows to sysdepends for the current stored procedure because it
depends on the missing object 'recur_sp'. The stored procedure will still be
created.
"Jack Vamvas" <DEL_TO_REPLYtechsupport@.ciquery.com> wrote in message
news:ELCdnem5EM1sDgLZRVnyvQ@.bt.com...
> We usually keep an "installation " table , when we save out stored
> procedures they are ordered by the stated execution order. (customised
> script)
>
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> ___________________________________
>
> "Alan" <alanpltseNOSPAM@.yahoo.com.au> wrote in message
> news:eXOzROPmGHA.4164@.TK2MSFTNGP03.phx.gbl...
>> I just use the 'Generate SQL Script' from EM to export stored procedure.
>> How do I export the Stored Procedure SQL Script in to a file so in an
> order
>> so that they can be created successfully ?
>> I got an error when execute the scripts:
>> Cannot add rows to sysdepends for the current stored procedure because it
>> depends on the missing object 'sp1'. The stored procedure will still be
>> created.
>> Cannot add rows to sysdepends for the current stored procedure because it
>> depends on the missing object 'sp2'. The stored procedure will still be
>> created.
>> ...............
>> ...............
>> How do I get around that ?
>>
>

Export SQL Role

Hi,
Is there a way to export a database role.
I would like to generate a script that I can apply to
another server.. This script would essentially create this
role for me without me having to manually create it, with
all its permissions.
Thanks.
Yes. Create a DTS Package Using Copy SQL Sever Objects Task. Go to the
Options button on the Copy tab and you'll see it. I've never used it, but
would assume it would copy permissions or else it would be no good IMO.
"niv" wrote:

> Hi,
> Is there a way to export a database role.
> I would like to generate a script that I can apply to
> another server.. This script would essentially create this
> role for me without me having to manually create it, with
> all its permissions.
> Thanks.
>

Export SQL Role

Hi,
Is there a way to export a database role.
I would like to generate a script that I can apply to
another server.. This script would essentially create this
role for me without me having to manually create it, with
all its permissions.
Thanks.Yes. Create a DTS Package Using Copy SQL Sever Objects Task. Go to the
Options button on the Copy tab and you'll see it. I've never used it, but
would assume it would copy permissions or else it would be no good IMO.
"niv" wrote:
> Hi,
> Is there a way to export a database role.
> I would like to generate a script that I can apply to
> another server.. This script would essentially create this
> role for me without me having to manually create it, with
> all its permissions.
> Thanks.
>

Export SQL Role

Hi,
Is there a way to export a database role.
I would like to generate a script that I can apply to
another server.. This script would essentially create this
role for me without me having to manually create it, with
all its permissions.
Thanks.Yes. Create a DTS Package Using Copy SQL Sever Objects Task. Go to the
Options button on the Copy tab and you'll see it. I've never used it, but
would assume it would copy permissions or else it would be no good IMO.
"niv" wrote:

> Hi,
> Is there a way to export a database role.
> I would like to generate a script that I can apply to
> another server.. This script would essentially create this
> role for me without me having to manually create it, with
> all its permissions.
> Thanks.
>

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...
> Perhaps 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
>>|||thanks but I would like to data too (copy the backup only is a
solution). But this script is very cool. Thanks|||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
>|||Thank you thomas. I will have a look on this tools.
Ina
Thomas 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
> >
> >

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
>

Export Schema and Data

This is a totally newbie question, but...

I've create a database, I'm able to script the schema to a query window, file, etc.

I can't for the life of me find out how to export my data so that it is scripted into insert statements. The data is standardized lists of data I will be distributing with the DB.

For those of you familiar with mySQL, this would be the output of the mysqldump command which dumps schema and data all into one file

mysqldumb <db> -u user -p > mydatafile.txt

thanks,

-David

You won't be able to export it to INSERT statements, but it can be exported to a flatfile with column and row delimiters. Please see Books Online topic bcp utility.

|||

Greg-

Ok, I'm familiar with BCP, was just trying to figure out a better way. I'll use BCP and either DTS or write a perl script to parse my data into scripted insert statements.

Thanks,

-David

|||

Well, you can always use TSQL to generate it for you as well, and save the results as a file. This can be expensive if your table is huge. Here's one example:

select 'INSERT into dbo.t1 (col1, col2, col3) values (''' + col1 + ''', ''' + col2 + ''', ' + cast(col3 as varchar(10)) + ')'

from dbo.t1

export roles and users into CSV

First of all, my SQL coding skills are not very good. Therefore I am
looking for a script which will export all SQL2k DB Roles (Application
& Database) including the Users (native SQL & AD Groups (we are using
mixed mode)) into a *.CSV.
thanks for your helpThat would be a nice Script to have.
In the meantime, try going to each database and selecting Generate Scripts.
Then only choose to scipt logins ?
that should be it,
Now to do it for one or more databases on one or more Servers.
Might have to try that on sunday
"Marty" <martin-za.frick@.ubs.com> wrote in message
news:fe528b81-5d2a-4732-93f3-ad47f8316644@.c33g2000hsd.googlegroups.com...
> First of all, my SQL coding skills are not very good. Therefore I am
> looking for a script which will export all SQL2k DB Roles (Application
> & Database) including the Users (native SQL & AD Groups (we are using
> mixed mode)) into a *.CSV.
> thanks for your help|||Hi Randy
Have a look at this link:
http://www.sqlservercentral.com/scripts/Maintenance+and+Management/31889/
Just need to build a DTS around the script and than adding it on each
DB server
On 13 Mrz., 16:55, "Randy Pitkin" <RandyPit...@.ydpages.com> wrote:
> That would be a nice Script to have.
> In the meantime, try going to each database and selecting Generate Scripts.
> Then only choose to scipt logins ?
> that should be it,
> Now to do it for one or more databases on one or more Servers.
> Might have to try that on sunday
> "Marty" <martin-za.fr...@.ubs.com> wrote in message
> news:fe528b81-5d2a-4732-93f3-ad47f8316644@.c33g2000hsd.googlegroups.com...
> > First of all, my SQL coding skills are not very good. Therefore I am
> > looking for a script which will export all SQL2k DB Roles (Application
> > & Database) including the Users (native SQL & AD Groups (we are using
> > mixed mode)) into a *.CSV.
> > thanks for your help

export roles and users into CSV

First of all, my SQL coding skills are not very good. Therefore I am
looking for a script which will export all SQL2k DB Roles (Application
& Database) including the Users (native SQL & AD Groups (we are using
mixed mode)) into a *.CSV.
thanks for your help
That would be a nice Script to have.
In the meantime, try going to each database and selecting Generate Scripts.
Then only choose to scipt logins ?
that should be it,
Now to do it for one or more databases on one or more Servers.
Might have to try that on sunday
"Marty" <martin-za.frick@.ubs.com> wrote in message
news:fe528b81-5d2a-4732-93f3-ad47f8316644@.c33g2000hsd.googlegroups.com...
> First of all, my SQL coding skills are not very good. Therefore I am
> looking for a script which will export all SQL2k DB Roles (Application
> & Database) including the Users (native SQL & AD Groups (we are using
> mixed mode)) into a *.CSV.
> thanks for your help
|||Hi Randy
Have a look at this link:
http://www.sqlservercentral.com/scripts/Maintenance+and+Management/31889/
Just need to build a DTS around the script and than adding it on each
DB server
On 13 Mrz., 16:55, "Randy Pitkin" <RandyPit...@.ydpages.com> wrote:[vbcol=seagreen]
> That would be a nice Script to have.
> In the meantime, try going to each database and selecting Generate Scripts.
> Then only choose to scipt logins ?
> that should be it,
> Now to do it for one or more databases on one or more Servers.
> Might have to try that on sunday
> "Marty" <martin-za.fr...@.ubs.com> wrote in message
> news:fe528b81-5d2a-4732-93f3-ad47f8316644@.c33g2000hsd.googlegroups.com...
>