SQLCLR is quite fast. Use it if you have a clear need to execute CLR code within T-SQL. For example, say you write a SQLCLR function with the signature:
SqlString Hash(SqlString input)
and you manage to get it all running the way it should. You could execute the following query:
IF EXISTS(SELECT * FROM Users WHERE HashedPassword = dbo.Hash(@userPassword) AND UserName = @userName)
BEGIN
SELECT 'You''re alright, Jack.';
END
ELSE
BEGIN
SELECT 'Bogus.';
END
If you can manage to hash the hypothetical password field in your app, you are better off to do so within the app and pass the hashed value into SQL Server to run a query like this:
SELECT *
FROM User
WHERE UserName = @userName AND HashedPassword = @hashedPassword
This is better for a few reasons:
- You aren't putting business logic into SQL Server, where it will be hard to test.
- The query itself is much less complicated, so SQL Server will be doing less work, and therefore be faster.
- Setting SQLCLR up can be a pain (SQLCLR is off by default). Deploying your assemblies into SQL Server can be a pain, especially if you don't have direct access to the production server.
- If you don't use SQLCLR, when you update/deploy your app, you won't have to remember to update/deploy the CLR stuff in SQL Server. This reduces your maintenance efforts.