SQL SERVER – BEGIN END VS BEGIN TRAN/COMMIT/ROLLBACK

Today I got an interesting question from Preethy kammath my colleague.

The question is what is the difference between BEGIN….END VS BEGIN TRAN/COMMIT/ROLLBACK?

The answer is

  • BEGIN…END

Begin……End delimits a block of code. IF there is no BEGIN TRAN inside the BEGIN…END then each statement will execute in an autonomous transaction.

  • BEGIN TRAN…COMMIT TRAN … Rollback

In this each statement inside this block is executed in the same transaction and cannot be committed or rolled back individually.

Hope every one understood the concept. More discussions are welcome.

SQL SERVER – Difference between Line Feed (\n) and Carriage Return (\r) – T-SQL New Line Char- New Line in T-SQL

Today one of friend named Aneesh come and asks me about the difference between Line Feed and carriage Return. To be frank I don’t know the technical term of for a new line in OS.I searched in the Google and got some good results. I will explain what I learnt from internet.

Line feed: ‘\n’

Carriage Return: ‘\r’

SQL SERVER 2005

In sql server 2005 both Line feed and Carriage will work separately.

SQL SERVER 2005

SQL SERVER 2008

In sql server 2008 combination of both Line feed and Carriage Return will only work.

SQL SERVER 2008

Thanks Aneesh for this wonderful simple and wonderful question.