-
-
Save JudsonMurray/10b45dff551c4f83cb456bc79bf3120b to your computer and use it in GitHub Desktop.
Get's a MD5 hash string for a stored procedure definition. This helps to check the integrity of a stored procedure over time Raw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IF OBJECT_ID('udf_GetProcedureHash', 'FN') IS NOT NULL | |
| BEGIN | |
| DROP FUNCTION udf_GetProcedureHash | |
| END | |
| GO | |
| CREATE FUNCTION udf_GetProcedureHash | |
| (@ProcedureName as sysname) | |
| RETURNS varchar(32) | |
| AS | |
| BEGIN | |
| DECLARE @ProcedureText As varchar(max), @Result As varchar(32) | |
| SET @ProcedureText = (SELECT OBJECT_DEFINITION (OBJECT_ID(@ProcedureName))) | |
| SELECT @Result = CONVERT(VARCHAR(32), HashBytes('MD5', @ProcedureText), 2) | |
| RETURN @Result | |
| END | |
| GO | |
| /* | |
| Test: | |
| SELECT dbo.udf_GetProcedureHash(name) As HashValue, name As ProcedureName FROM sys.procedures; | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment