Forum Discussion

iainr65's avatar
iainr65
Copper Contributor
Jan 27, 2025

Altering sql object definitions

Hi, I have a few objects, such as stored procedures, views, and inline table valued functions, that I'd like to modify. Currently they contain select references to sales.orderstest table, and I'd like to change the text to Sales.Orders. I'd like to do this with either tsql or powershell. In other words, for functions for instance, I'd like a script (tsql or powershell), to get a list of all functions in the specified database (use a parameter to get the database info), extract the object definition, and where it findes 'Sales.Orderstest' references, it replaces with 'Sales.Orders'

I’d rather do this with one script rather than opening each function independently and modifying them manually.

Any hints, or pointers would be most appreciated.