Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lundeen-bryan/a307431474e8cfa43274093be75a6261 to your computer and use it in GitHub Desktop.
Save lundeen-bryan/a307431474e8cfa43274093be75a6261 to your computer and use it in GitHub Desktop.
snippet for creating a stored sql procedure
{
"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