Introduction

Before comparing the performance of SQLCLR and TSQL, look at the definition of SQLCLR.

SQLCLR

SQLCLR is the Microsoft name for integrating CLR as a hosted runtime within SQL SERVER. It enables the execution of managed code inside the database.

Architecture of SQLCLR

sql.gif

T-SQL is nothing but Transact SQL, which is the native language supported by SQL SERVER.

CLR supported in SQL Server provides an alternative to the procedural approach in T-SQL.

Now the question comes when to choose SQLCLR and when to choose T-SQL for the procedural approach. We can't blindly decide because each approach has strengths and weaknesses. So the decision should be made judiciously.

Thumb Rule

Comparison of String Split functionality

We need to split out strings in a string that has a delimiter and should be returned as a set of rows. This functionality is tested with the above two approaches, and the result is as follows.

Result - SQLCLR - Performs three times faster than T-SQL.

So in this scenario, SQLCLR performs better with minimum code.

So choosing the right one for the right scenario performs the best.