Introduction
This article demonstrates how to create an encrypted Stored Procedure in SQL Server. This article starts with an introduction to the creation of a Stored Procedure in SQL Server. Then, it demonstrates how to encrypt a Stored Procedure.
Every developer wants the security of her/his SQL code like a Stored Procedure. For this, we will go for encryption. Encryption is a good but not utterly tenable process. In this article, I would like to show you some best practices for encrypting SQL Server code.
Creating a normal Stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Gaurav Malviya
-- Create date: 12-01-2014
-- Description: un-Encrypt Stored Procedure
-- =============================================
CREATE PROCEDURE sp_gettestdata
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT * FROM test_table
END
GO
For Check Stored Procedure.

Encrypt Stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Gaurav Malviya
-- Create date: 12-01-2014
-- Description: Encrypt Stored Procedure
-- =============================================
CREATE PROCEDURE sp_gettestdataEncrypt
WITH ENCRYPTION
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
SET NOCOUNT ON;
SELECT * FROM test_table
END
GO
Again Check Stored Procedure.

Summary
In this article, I showed how to encrypt a Stored Procedure in SQL Server. We then saw how to set an image to get code with the help of a sp_helptext command.

Bhupendra SinghPosted Apr 15, 2014, 4:31 AM
if i want to change some logics in existing store procedure.it is possible.
Gaurav MalviyaPosted Jan 14, 2014, 10:02 AM
because if we deploying any application to the client end we don't want to sow your logics that's why we do this .
Keyur PatelPosted Jan 14, 2014, 4:52 AM
Really Nice but i am bit confused, why we need to encrypt our store procedure. Did you get any specific requirements to encrypt store procedure. I want to to know real word requirement.
Gaurav MalviyaPosted Jan 13, 2014, 11:28 AM
Bhupendra, You need to connect via the DAC. See the file "Decrypt SQL stored procedures, functions, triggers, views.sql" in http://www.sqlmag.com/content/content/95728/95728.zip
Gaurav MalviyaPosted Jan 13, 2014, 11:25 AM
Mahesh Chand, There should be. If there wasn't the encryption/decryption wasn't doing anything. The overhead should, however, be a constant time slight overhead, and should be negligible in larger transactions.
Mahesh ChandPosted Jan 13, 2014, 7:18 AM
Are there any advantages of encrypting a stored procedure? Is there any performance problem? Thanks!
Bhupendra SinghPosted Jan 13, 2014, 6:18 AM
HOW to decrypt store procedure .