Created
October 23, 2024 19:52
-
-
Save lundeen-bryan/a307431474e8cfa43274093be75a6261 to your computer and use it in GitHub Desktop.
snippet for creating a stored sql procedure
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
Show hidden characters
{ | |
"Add Logging to Stored Procedure":{ | |
"prefix": "addlogging", | |
"body": [ | |
"CREATE PROCEDURE ${1:ProcedureName}", | |
"AS", | |
"BEGIN", | |
" --Log procedure execution", | |
" INSERT INTO ProcedureUsageLog(ProcedureName, ExecutionTime, DBName)", | |
" VALUES('$1', GETDATE(), DB_NAME();", | |
"", | |
" -- Original procedure logic", | |
" $2", | |
"END", | |
], | |
"description": "Add logging to stored procedures" | |
}, | |
"dropandcreateprocedurewithlogging":{ | |
"prefix": "logusp", | |
"body": [ | |
"--drop procedure if it exists", | |
"if object_id('${1:schemaname}.${2:uspprocedurename}','p') is not null", | |
"drop procedure ${1:schemaname}.${2:uspprocedurename}", | |
"as", | |
"begin", | |
" -- call the centralized logging procedure", | |
" exec ${1:schemaname}.usplogprocedureaccess '${2:uspprocedurename}';", | |
"", | |
" -- procedure logic below here", | |
"end;" | |
], | |
"description": "drop, create and log stored procedure" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment