I have written a stored procedure in SQL Server.
Now its just that I don\'t want any one to see my script or edit it.
Please remember that I am working on the a
Use the encryption
keyword for your stored procedure. This will hide the code:
CREATE PROCEDURE dbo.foo
WITH ENCRYPTION
AS
BEGIN
SELECT 'foo'
END
SQL Server doesn't truly provide a foolproof method to protect module code. The WITH ENCRYPTION
clause should be named something along the lines of WITH LOOSE_OBFUSCATION
, since the "encryption" is very easily thwarted. You're not going to be able to use anything in SQL Server to make the code undecipherable by anyone except the most casual onlookers - anyone determined is going to be able to beat native methods without breaking a sweat.
While this may be good enough for your needs, probably a safer way (but still not perfect) is to put some or all of the procedure's business logic into the CLR (read more here).
You're looking for WITH ENCRYPTION
, which encrypts the code behind your stored proc.
CREATE PROCEDURE usp_MyProc
WITH ENCRYPTION
AS
SELECT *
FROM myTable
Just a caveat, from MSDN:
Users who have no access to system tables or database files cannot retrieve the obfuscated text. However, the text will be available to privileged users who can either access system tables over the DAC port or directly access database files.
Some references and further reading:
Avoid using the WITH ENCRYPTION
option other than for very specified requirements. It may lead to administrative problems later.
Using WITH ENCRYPTION
is not a recommended best practice to hide the definition/code of an object. Luckily, there is an alternative approach for SQL Server.
If it is required to hide the definition/code of any object from a user then standard permissions can be used for this purpose. This can be done by granting or revoking View Definition rights.
If permission View Definition is denied for an object to any user then the user would not be able to view the object in SSMS or view its code through the system stored procedure sp_helptext
.
The View Definition permission may also be used for other objects in SQL Server like tables, synonyms etc. View Definition permissions can be granted or denied using both T-SQL
or SSMS
For implementation of permissions through SSMS :
Denying View Definition
permission will hide the object for a specific user and also the user will not be able to see the definition using sp_helptext
Other permissions like SELECT, INSERT
etc will remain intact.
The permissions are flexible and can be implemented on the following four levels:
Thank you hope it will clear confusion.