开发者

How to remove 'enters' from TSQL scripts executed in Microsoft SQL Server Management Studio?

开发者 https://www.devze.com 2023-02-16 18:23 出处:网络
I\'m working with a lot of TSQL scripts that perform management tasks on the SQL Server. Those scripts are saved as .sql files and executed by a DBA in Microsoft SQL Server Management Studio. I use th

I'm working with a lot of TSQL scripts that perform management tasks on the SQL Server. Those scripts are saved as .sql files and executed by a DBA in Microsoft SQL Server Management Studio. I use the print statement to echo some information back to the DBA.

Consider the following simplification of a script:

PRINT 'Update user...'
UPDATE [User] SET U开发者_运维问答serName = UserName WHERE UserName = 'Administrator' 

PRINT 'Delete user...'
DELETE FROM [User] WHERE UserName = 'Nothing' 

PRINT 'Update & Delete finished'

When I'm running this script I get the following output:

Update user...

(1 row(s) affected)
Delete user...

(0 row(s) affected)
Update & Delete finished

There is always an enter before the result of the query. Some of my DBA's are complaining about the readability of the output. It is especially hard to interpret the results when a cursor is used in a script.

Is there a way to get rid of the preceding enters when the result of an action is displayed?


You could SET NOCOUNT ON , get the rows affected via @@ROWCOUNT and print a custom message yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消