Wednesday, March 7, 2012

Generate Script Problem

Hi,

When I run the "Generate Scripts.." wizard to generate Stored Procs, they are displayed with all the single quotes replaced by two single quotes and a few additional single quotes here and there. The problem is, I can not take this stored proc and run it in another DB as you can see it from the example below. Do I need to be picking any particular settings?

SET ANSI_NULLS OFF

GO

SET QUOTED_IDENTIFIER OFF

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[getQuestions]') AND type in (N'P', N'PC'))

BEGIN

EXEC dbo.sp_executesql @.statement = N'

/*************************************************************************************

Stored Proc Desription:

*************************************************************************************/

CREATE PROCEDURE [dbo].[getQuestions]

AS

SELECT a, b, c FROM Country WHERE countrycode=''US''

'

END

The above is not a problem. Please ignore this post. Everything works as intended.

Generate script of ALL database objects

I need to be able to programatically generate the CREATE scripts for all objects for a given database. Basically, I need the same results as if I generated the script using SSMS and choosing to script all objects in the selected database.

I'm hoping I could do this using the Scripter w/in the SMO Utility Classes. Can anyone help me out?

Thanks in advance!Hi,

use the transfer method of the scripter:

http://blogs.msdn.com/mwories/articles/smosample_transfer.aspx

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||Thanks Jens. Just what I was looking for. :-)|||Take a look at this free tool -- it scripts out all database objects in a manner which mimics Visual Studio for Database Professionals [the "Data Dude"]. That is, it creates a separate file for each object in the database in an organized file tree.

http://sourceforge.net/projects/script-sql-db

Richard|||Would anyone happen to know how I could get the end of a batch of Transact-SQL statements; i.e "GO" statements to show up in generated script?

Thanks.|||As you get a stringCollection using the

System.Collections.Specialized.StringCollection s = t.ScriptTransfer(); // Or use ScriptTransfer() if you need to capture the script (without data)

You can simply modify the script on your own.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Well, yes, I see your point, but then wouldn't I have to write a decent amount of conditional code to to determine if I need a "GO" line or not? Assuming I would not want a "GO" statement on each line as I'd like to batch some of the operations.

I noticed that the scripter object generates code with the embedded "GO" statements, does the transfer object not provide this capability?

Thanks.|||There is a property in the Transfer object named 'FileName'. When you supply this property with a file path the generated script is output to a text file and the 'GO' statements are in the text file.

Generate script of ALL database objects

I need to be able to programatically generate the CREATE scripts for all objects for a given database. Basically, I need the same results as if I generated the script using SSMS and choosing to script all objects in the selected database.

I'm hoping I could do this using the Scripter w/in the SMO Utility Classes. Can anyone help me out?

Thanks in advance!Hi,

use the transfer method of the scripter:

http://blogs.msdn.com/mwories/articles/smosample_transfer.aspx

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||Thanks Jens. Just what I was looking for. :-)|||Take a look at this free tool -- it scripts out all database objects in a manner which mimics Visual Studio for Database Professionals [the "Data Dude"]. That is, it creates a separate file for each object in the database in an organized file tree.

http://sourceforge.net/projects/script-sql-db

Richard|||Would anyone happen to know how I could get the end of a batch of Transact-SQL statements; i.e "GO" statements to show up in generated script?

Thanks.|||As you get a stringCollection using the

System.Collections.Specialized.StringCollection s = t.ScriptTransfer(); // Or use ScriptTransfer() if you need to capture the script (without data)

You can simply modify the script on your own.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Well, yes, I see your point, but then wouldn't I have to write a decent amount of conditional code to to determine if I need a "GO" line or not? Assuming I would not want a "GO" statement on each line as I'd like to batch some of the operations.

I noticed that the scripter object generates code with the embedded "GO" statements, does the transfer object not provide this capability?

Thanks.|||There is a property in the Transfer object named 'FileName'. When you supply this property with a file path the generated script is output to a text file and the 'GO' statements are in the text file.

Generate Script including Data

Hello Group:
Is there any way of generate a script which include data and database
structure in SQL SERVER 2000?
Thanks in advance.
Armando
http://www.karaszi.com/SQLServer/inf...ate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Armando Ruiz" <armando-ruiz@.telefonica.net> wrote in message
news:OfzTF$7AFHA.1992@.TK2MSFTNGP10.phx.gbl...
> Hello Group:
> Is there any way of generate a script which include data and database
> structure in SQL SERVER 2000?
> Thanks in advance.
> Armando
>
|||Hi Armando,
Would you be able to tell us the exact purpose? There are other better ways
to do it.
Thanks
Yogish
|||Hello and thanks for your quick answers.
I've to update a remote MSDE database, creating 4 new tables and inserting
data.
I cant use DTS, Export Data, etc., so I'm looking an easy way to update
that database only by 1 step.
Thanks again
Armando
"Yogish" <yogishkamathg@.icqmail.com> escribi en el mensaje
news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> Hi Armando,
> Would you be able to tell us the exact purpose? There are other better
ways
> to do it.
> --
> Thanks
> Yogish
|||check out DB Ghost - http://www.dbghost.com for scripting, building,
comparing and synchronizing both schema and data optionally using Source
control.
"Armando Ruiz" wrote:

> Hello and thanks for your quick answers.
> I've to update a remote MSDE database, creating 4 new tables and inserting
> data.
> I can′t use DTS, Export Data, etc., so I'm looking an easy way to update
> that database only by 1 step.
> Thanks again
> Armando
>
> "Yogish" <yogishkamathg@.icqmail.com> escribió en el mensaje
> news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> ways
>
>
|||Thanks for the reply .
"mark baekdal" <markbaekdal@.discussions.microsoft.com> escribi en el
mensaje news:8F801F86-AD4A-4D1C-90CA-4CC4619D86FB@.microsoft.com...[vbcol=seagreen]
> check out DB Ghost - http://www.dbghost.com for scripting, building,
> comparing and synchronizing both schema and data optionally using Source
> control.
> "Armando Ruiz" wrote:
inserting[vbcol=seagreen]

Generate Script including Data

Hello Group:
Is there any way of generate a script which include data and database
structure in SQL SERVER 2000?
Thanks in advance.
Armandohttp://www.karaszi.com/SQLServer/in...rate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Armando Ruiz" <armando-ruiz@.telefonica.net> wrote in message
news:OfzTF$7AFHA.1992@.TK2MSFTNGP10.phx.gbl...
> Hello Group:
> Is there any way of generate a script which include data and database
> structure in SQL SERVER 2000?
> Thanks in advance.
> Armando
>|||Hi Armando,
Would you be able to tell us the exact purpose? There are other better ways
to do it.
Thanks
Yogish|||Hello and thanks for your quick answers.
I've to update a remote MSDE database, creating 4 new tables and inserting
data.
I cant use DTS, Export Data, etc., so I'm looking an easy way to update
that database only by 1 step.
Thanks again
Armando
"Yogish" <yogishkamathg@.icqmail.com> escribi en el mensaje
news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> Hi Armando,
> Would you be able to tell us the exact purpose? There are other better
ways
> to do it.
> --
> Thanks
> Yogish|||check out DB Ghost - http://www.dbghost.com for scripting, building,
comparing and synchronizing both schema and data optionally using Source
control.
"Armando Ruiz" wrote:

> Hello and thanks for your quick answers.
> I've to update a remote MSDE database, creating 4 new tables and inserting
> data.
> I can′t use DTS, Export Data, etc., so I'm looking an easy way to update
> that database only by 1 step.
> Thanks again
> Armando
>
> "Yogish" <yogishkamathg@.icqmail.com> escribió en el mensaje
> news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> ways
>
>|||Thanks for the reply .
"mark baekdal" <markbaekdal@.discussions.microsoft.com> escribi en el
mensaje news:8F801F86-AD4A-4D1C-90CA-4CC4619D86FB@.microsoft.com...[vbcol=seagreen]
> check out DB Ghost - http://www.dbghost.com for scripting, building,
> comparing and synchronizing both schema and data optionally using Source
> control.
> "Armando Ruiz" wrote:
>
inserting[vbcol=seagreen]

Generate Script including Data

Hello Group:
Is there any way of generate a script which include data and database
structure in SQL SERVER 2000?
Thanks in advance.
Armandohttp://www.karaszi.com/SQLServer/info_generate_script.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Armando Ruiz" <armando-ruiz@.telefonica.net> wrote in message
news:OfzTF$7AFHA.1992@.TK2MSFTNGP10.phx.gbl...
> Hello Group:
> Is there any way of generate a script which include data and database
> structure in SQL SERVER 2000?
> Thanks in advance.
> Armando
>|||Hi Armando,
Would you be able to tell us the exact purpose? There are other better ways
to do it.
--
Thanks
Yogish|||Hello and thanks for your quick answers.
I've to update a remote MSDE database, creating 4 new tables and inserting
data.
I can´t use DTS, Export Data, etc., so I'm looking an easy way to update
that database only by 1 step.
Thanks again
Armando
"Yogish" <yogishkamathg@.icqmail.com> escribió en el mensaje
news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> Hi Armando,
> Would you be able to tell us the exact purpose? There are other better
ways
> to do it.
> --
> Thanks
> Yogish|||check out DB Ghost - http://www.dbghost.com for scripting, building,
comparing and synchronizing both schema and data optionally using Source
control.
"Armando Ruiz" wrote:
> Hello and thanks for your quick answers.
> I've to update a remote MSDE database, creating 4 new tables and inserting
> data.
> I can´t use DTS, Export Data, etc., so I'm looking an easy way to update
> that database only by 1 step.
> Thanks again
> Armando
>
> "Yogish" <yogishkamathg@.icqmail.com> escribió en el mensaje
> news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> > Hi Armando,
> >
> > Would you be able to tell us the exact purpose? There are other better
> ways
> > to do it.
> >
> > --
> > Thanks
> > Yogish
>
>|||Thanks for the reply .
"mark baekdal" <markbaekdal@.discussions.microsoft.com> escribió en el
mensaje news:8F801F86-AD4A-4D1C-90CA-4CC4619D86FB@.microsoft.com...
> check out DB Ghost - http://www.dbghost.com for scripting, building,
> comparing and synchronizing both schema and data optionally using Source
> control.
> "Armando Ruiz" wrote:
> > Hello and thanks for your quick answers.
> >
> > I've to update a remote MSDE database, creating 4 new tables and
inserting
> > data.
> >
> > I can´t use DTS, Export Data, etc., so I'm looking an easy way to update
> > that database only by 1 step.
> >
> > Thanks again
> >
> > Armando
> >
> >
> >
> > "Yogish" <yogishkamathg@.icqmail.com> escribió en el mensaje
> > news:E9EBED22-3D66-4DCB-B91E-8DCF5FAE25A8@.microsoft.com...
> > > Hi Armando,
> > >
> > > Would you be able to tell us the exact purpose? There are other better
> > ways
> > > to do it.
> > >
> > > --
> > > Thanks
> > > Yogish
> >
> >
> >

Sunday, February 26, 2012

Generate Script in SQL 2005

In SQL2K, we can generate scripts just for PK and FK, or just Indexes.
Somehow, I could not to do that in SQL 2005, it does not give me the options
to generate only Indexes.
Any idea?This is a severe shortcoming in the tool (both not being able to right-click
the indexes node under a table and script all, and not being able to select
multiple items anywhere in Object Explorer). But thankfully, there is help
coming soon with Service Pack 2, which swaps out the Summary tab for a new
context-sensitive tab called Object Explorer Details. In this tab, when you
expand a table and highlight the Indexes node on the left, you can select
multiple items on the right, right-click them, and follow a Script > menu.
I talked about this briefly here:
http://www.aaronbertrand.com/rant.asp?r=499
"TBoon" <allblacks15@.hotmail.com> wrote in message
news:uo0a3dODHHA.4404@.TK2MSFTNGP03.phx.gbl...
> In SQL2K, we can generate scripts just for PK and FK, or just Indexes.
> Somehow, I could not to do that in SQL 2005, it does not give me the
> options to generate only Indexes.
> Any idea?
>|||In addition to Aaron's, post:
Meanwhile, consider doing some SMO coding: http://www.karaszi.com/SQLServer/info_generate_script.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"TBoon" <allblacks15@.hotmail.com> wrote in message news:uo0a3dODHHA.4404@.TK2MSFTNGP03.phx.gbl...
> In SQL2K, we can generate scripts just for PK and FK, or just Indexes.
> Somehow, I could not to do that in SQL 2005, it does not give me the options to generate only
> Indexes.
> Any idea?
>|||Hi,Aaron
Hmm, it is possible that I do not understand you , but I can highlight more
than one item (SPfor example) in Object Explorer and script them out to the
new window
I have SQL Server 2005 Dev Edition
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23GNKeHPDHHA.3524@.TK2MSFTNGP06.phx.gbl...
> This is a severe shortcoming in the tool (both not being able to
> right-click the indexes node under a table and script all, and not being
> able to select multiple items anywhere in Object Explorer). But
> thankfully, there is help coming soon with Service Pack 2, which swaps out
> the Summary tab for a new context-sensitive tab called Object Explorer
> Details. In this tab, when you expand a table and highlight the Indexes
> node on the left, you can select multiple items on the right, right-click
> them, and follow a Script > menu.
> I talked about this briefly here:
> http://www.aaronbertrand.com/rant.asp?r=499
>
>
>
> "TBoon" <allblacks15@.hotmail.com> wrote in message
> news:uo0a3dODHHA.4404@.TK2MSFTNGP03.phx.gbl...
>> In SQL2K, we can generate scripts just for PK and FK, or just Indexes.
>> Somehow, I could not to do that in SQL 2005, it does not give me the
>> options to generate only Indexes.
>> Any idea?
>|||I don't know how you could do that. When I click on an object like a table,
and hold shift or control to try and click a second table, the second table
is highlighted (even if I am still holding shift or control).
Maybe you could take a screen shot of what you are talking about, because I
don't know of any node in Object Explorer that allows this (SP2 or prior).
We're talking about Management Studio here, right? Not Query Analyzer?
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%23B5w9lSDHHA.3228@.TK2MSFTNGP03.phx.gbl...
> Hi,Aaron
> Hmm, it is possible that I do not understand you , but I can highlight
> more than one item (SPfor example) in Object Explorer and script them out
> to the new window
> I have SQL Server 2005 Dev Edition|||Hi ,Aaron
> We're talking about Management Studio here, right? Not Query Analyzer?
Sure , here is the morning , but I had already two coffees :-))))))
>I don't know how you could do that. When I click on an object like a
>table, and hold shift or control to try and click a second table, the
>second table is highlighted (even if I am still holding shift or control).
In Summery Tab I click on SP --hold Ctrl button and then secon SP --
I can send you a print screen if you want , just tell me the email address
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:ONxNC3SDHHA.3524@.TK2MSFTNGP06.phx.gbl...
>I don't know how you could do that. When I click on an object like a
>table, and hold shift or control to try and click a second table, the
>second table is highlighted (even if I am still holding shift or control).
> Maybe you could take a screen shot of what you are talking about, because
> I don't know of any node in Object Explorer that allows this (SP2 or
> prior).
> We're talking about Management Studio here, right? Not Query Analyzer?
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:%23B5w9lSDHHA.3228@.TK2MSFTNGP03.phx.gbl...
>> Hi,Aaron
>> Hmm, it is possible that I do not understand you , but I can highlight
>> more than one item (SPfor example) in Object Explorer and script them out
>> to the new window
>> I have SQL Server 2005 Dev Edition
>|||> In Summery Tab
(!) I was talking about Object Explorer (the left pane). I never used the
Summary Tab.
And as luck would have it, I don't have a pre-SP2 server within reach to
even see what you're talking about. Again, I was talking about in Object
Explorer, which I had initially expected to allow you to select multiple
objects.
A|||Ok,
I was confused by your statement
<coming soon with Service Pack 2, which swaps out the >Summary tab for a new
> context-sensitive tab called Object Explorer Details.
Well, I just wanted to say that on the righ pane (Summary Tab) you can do
that
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:e0aKhcXDHHA.1196@.TK2MSFTNGP02.phx.gbl...
>> In Summery Tab
> (!) I was talking about Object Explorer (the left pane). I never used the
> Summary Tab.
> And as luck would have it, I don't have a pre-SP2 server within reach to
> even see what you're talking about. Again, I was talking about in Object
> Explorer, which I had initially expected to allow you to select multiple
> objects.
> A
>