Archive for November, 2012

Download SQL Server 2012 Service Pack 1 (SP1)

The Microsoft has released the first service pack (SP1) for the SQL Server 2012 today. Here goes the link to download SQL Server 2012 SP1

Though, we have got 8 files with this release, we would require following files in order to run the service pack 1:

  • For 64-bit SQL Server, download file: SQLServer2012SP1-KB2674319-x64-ENU.exe
  • For 32-bit SQL Server, download file: SQLServer2012SP1-KB2674319-x86-ENU.exe

Other .exe files in this release is used for special purposes.


Difference Between RAISERROR and THROW in SQL Server

As we all know that both the RAISERROR and THROW statements are used to raise an error in T-SQL block. However, the quesion arises is if both do the same job, why do we have the two different statements?

So, let us take a look at the difference between the two statements.

RAISERROR Statement THROW Statement
Ancient statement supported by the SQL Server. New statement introduced in the SQL Server 2012.
Little complex statement, offers more features. Very simple statement, offers limited features.
Message string offers printf style formatting. Message string does not offer printf style foramtting.
Can generate user-defined i.e. msg_id > 50000 as well as system-defined i.e. msg_id < 50000 errors. Can only generate user-define i.e. msg_id > 50000 errors.
If Message ID is used, it must be defined in sys.messages catalog view. If Message Number is used, it may not be defined in sys.messages catalog view.
Different severity level can be defined with this statement. It does not allow to set different severity level. It always has severity level 16.
It does not require preceding statement to end with semicolon (;) statement terminator. It requires preceding statement to end with semicolon (;) statement terminator.

Hope it helps us out to understand difference between these two statements.

Using THROW in SQL Server 2012

SQL Server 2012 has introduced a simplified version of RAISERROR statement i.e. THROW statement.

The THROW statement raises a run-time error and accepts three parameters. It’s easier to implement this statement without much hassle. Take a look at below the syntax.

Let me explain the parameters/agruments.

error_number: This is of int data type and represents the error. It value must be 50000 through 2147483647.

Read more…

Using RAISERROR in SQL Server

The RAISERROR statement is used to intentionally raise an error in the T-SQL block. It can be used anywhere i.e. outside the TRY…CATCH block or inside the TRY block or inside CATCH block or inside the TRY and the CATCH block as well. 

Generally, we use it to raise a user-defined error in the T-SQL block like inside a Stored Procedure code.

Take a look at below the RAISERROR statement syntax.

Let me explain the parameters/arguments.

Read more…

Using RETURN Keyword in SQL Server

As the word “RETURN” implies, it returns a value of INTEGER data type.

It is primarily used in Stored Procedures. It exits a T-SQL query or Stored Procedure immediately, leaving all subsequent T-SQL statements following it.

As we all know that Stored Procedure always returns an INTEGER value indicating whether it succeeded or not. Zero value indicates success and non-zero value indicates failure.

If we wish to return a value to called of the Stored Procedure, we may use RETURN statement. Else, it returns zero by default.

Take a look at an example below.

Read more…

Using GOTO Keyword in SQL Server

It is used to alter the current execution and send the execution to a particular label name. We can use it in procedure, batch or statement block. It skips all the statements following it and executes the statement where label name is encountered.

It, of course, can also be nested.

Take a look at an example below.

Using CONTINUE Keywork in SQL Server

It is primarily used with the WHILE loop. It restarts the WHILE loop, ignoring all statements after it.

Take a look at an example below.