I would like to share my experience on how to find out dependencies between a table's field name and stored procedures or functions.
I often encounter situations that require database schema changes to meet business requirement changes. For example, changing the name for some fields. It might be an easy thing if the database is small and not used for a complex front-end. However, in my cases, changing a field's name often means:
- table schema change
- stored procedures change
- functions change
- data access layer code change
- data presentation layer code change
At least the first three are in the SQL scope, and it would be time consuming if we have to open each stored procedure or function and search from there.
This script is not complicated but rather a handy tool. It will list all the stored procedures and functions that contains the given keyword passed as a parameter, and will further indicate if the keyword is actually used as a parameter. This is important because it helps me to find out what functions are related to it in my data access layer code.
There are some limitations:
- All my stored procedures start with sp or dd, so you should modify the script to meet your own situation.
- All my stored procedures are no longer than 3000 characters, so if you have a longer one, please increase the parameter in the script.
- Keyword length is set to varchar(20). You can increase it by modifying the script if you want to search for a longer keyword.