devxlogo

Encrypting Stored Procedures

Encrypting Stored Procedures

When creating stored procedures, there will be occasions where a certain procedure definition should not be viewed. Using the WITH ENCRYPTION clause stores the procedure definition in an unreadable form. After the definition of the stored procedure is encrypted, it cannot be decrypted nor viewed by anyone, including the owner of the stored procedure and the system administrator.
Sample code:

 --------------- Create Stored Procedure --------------CREATE PROC SPtest WITH ENCRYPTIONASSELECT [CustomerID], [CompanyName], [ContactName],       [ContactTitle], [Address], [City], [Region],       [PostalCode], [Country], [Phone], [Fax]FROM [Northwind].[dbo].[Customers]--------------------------------------------------------------------- Execute Stored Procedure -------------DECLARE @RC int-- Set parameter valuesEXEC @RC = [Northwind].[dbo].[SPtest]------------------------------------------------------

size=3>
When a user attempts to open the created stored procedure using SQL Server 2000, Error 20585 is produced stating that the encrypted object is not transferable, and script cannot be generated.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist