|
|
|
date: Fri, 30 May 2008 09:07:11 +0200,
group: microsoft.public.sqlserver.tools
back
Re: About PRINT and other SQLCMD questions
Just another question on this topic...
Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:
BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO
Then my question is, would the approach you mentioned with @@transcount work
here as well? or does it get "broken" by the fact that two child scripts
(:r) are sourced?
http://www.panamasights.com
http://www.virtual-aviation.info
----- Original Message -----
From: "Erland Sommarskog"
Newsgroups: microsoft.public.sqlserver.tools
Sent: Saturday, May 31, 2008 12:15 AM
Subject: Re: About PRINT and other SQLCMD questions
> ....DotNet4Ever.... (hate.spam@nowhere.com) writes:
>> I am using SQLCMD.EXE of SQL Server 2005 for the automation of my
>> installation scripts. I wanted to make use of transactions when inserting
>> data into the database during the installation but since there are
>> several
>> GO in between it was not possible without having to multiplicate the
>> BEGIN/END TRANSACTION.
>
> Transactions can span batches. What you need to consider is that each
> batch that is intended to be part of the transaction is formed like
> this:
>
> IF @@trancount > 0
> BEGIN
> .....
> END
>
> This is because an error in a previous batch may abort the batch and
> roll back any open transactions.
>
>
>> 3) Does the PRINT 'any message' gets automatically flushed to the output
>> stream or do I always have to use GO after it to make sure it is flushed
>> before continuing? I need to print these messages (and thus have the user
>> read them) BEFORE the action is performed, if it remains in the cache
>> then
>> the user feedback is lost. I wanted to avoid having GO after a plain old
>> PRINT.
>
> Use RAISERROR('My message', 0, 1) WITH NOWAIT instead of PRINT to
> address this problem.
>
> Sorry, I don't have the answer for the other two questions.
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
"Erland Sommarskog" wrote in message
news:Xns9AAF2B03DF54Yazorman@127.0.0.1...
> ....DotNet4Ever.... (hate.spam@nowhere.com) writes:
>> I am using SQLCMD.EXE of SQL Server 2005 for the automation of my
>> installation scripts. I wanted to make use of transactions when inserting
>> data into the database during the installation but since there are
>> several
>> GO in between it was not possible without having to multiplicate the
>> BEGIN/END TRANSACTION.
>
> Transactions can span batches. What you need to consider is that each
> batch that is intended to be part of the transaction is formed like
> this:
>
> IF @@trancount > 0
> BEGIN
> .....
> END
>
> This is because an error in a previous batch may abort the batch and
> roll back any open transactions.
>
>
>> 3) Does the PRINT 'any message' gets automatically flushed to the output
>> stream or do I always have to use GO after it to make sure it is flushed
>> before continuing? I need to print these messages (and thus have the user
>> read them) BEFORE the action is performed, if it remains in the cache
>> then
>> the user feedback is lost. I wanted to avoid having GO after a plain old
>> PRINT.
>
> Use RAISERROR('My message', 0, 1) WITH NOWAIT instead of PRINT to
> address this problem.
>
> Sorry, I don't have the answer for the other two questions.
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
date: Tue, 3 Jun 2008 13:16:15 +0200
author: ....DotNet4Ever....
|
|