question

user-69 avatar image
user-69 asked

What is the SQL Server equivalent of ‘psql’

In PostgreSQL the ‘psql’ client lets you run interactive transactions, e.g.

Begin;
Update ...
Select ...
(oops)
rollback

Where is the same thing in SQL Server?

transactionpostgresqllinux
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Steve Jones - Editor avatar image
Steve Jones - Editor answered

osql (http://msdn.microsoft.com/en-us/library/aa214012%28SQL.80%29.aspx) or SQLCMD (http://msdn.microsoft.com/en-us/library/ms162773.aspx) are the equivalent command line tools in SQL Server. I guess Management Studio (SSMS), might be considered the client as well.

SSMS is a GUI client.

SQLCMD and OSQL are command line tools.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

Some T-SQL editors include a test mode that will wrap your statements in BEGIN / ROLLBACK statements for you (with varying degrees of protection to what you are doing within those statements). SSMS certainly doesn't have it built in - I'm not sure if any plug-ins give you that functionality off the top of my head.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jorge Segarra avatar image
Jorge Segarra answered

For error checking purposes you might want to look into the TRY/CATCH block:

http://msdn.microsoft.com/en-us/library/ms175976.aspx

But in T-SQL (Transact SQL) we do have the ROLLBACK TRANSACTION like you posted above:

http://msdn.microsoft.com/en-us/library/ms181299.aspx

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image
Scot Hauder answered

@Matt @phil I think you're looking for: SET IMPLICIT_TRANSACTIONS ON

2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

That's different really, and it would be IMPLICIT_TRANSACTIONS ON that would always run a transaction but never commit it without an explicit user commit.
0 Likes 0 ·
ON, thank you, I was a little out of it last night :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.