The column name is wrong, and changing it looks like a one line fix. Renaming a column safely means finding every place that still asks for the old name.

Map Consumers Before Renaming a Column
Start with the table, schema, old column, and proposed new name. Search views, procedures, functions, triggers, jobs, report datasets, ETL packages, and application queries. A database dependency view is useful but cannot see every dynamic SQL string or external consumer.
I ask whether the column appears in SELECT *, insert column lists, joins, or report expressions. Each usage has a different failure mode. A SELECT * consumer can keep running with a changed column name while downstream code that expects the old alias fails later.
Document the contract before editing. Is the rename internal, or does an application API expose the column name? If outside consumers cannot change together, plan a compatibility period with a view or alias. Quickly renaming a column in the base table does not make the ecosystem quick.
SELECT OBJECT_SCHEMA_NAME(referencing_id) AS referencing_schema,
OBJECT_NAME(referencing_id) AS referencing_object,
referenced_entity_name,
COL_NAME(referenced_id, referenced_minor_id) AS referenced_column
FROM sys.sql_expression_dependencies
WHERE referenced_id = OBJECT_ID(N'dbo.Customer');Search Definitions and External Code
Search sys.sql_modules for the old name, then inspect matches manually. A text match can be a comment or another column with the same spelling. A dependency row can miss dynamic SQL. Use both forms of evidence, plus a search of application and report source files.
I keep an inventory with object name, owner, planned change, and test. That turns a broad search into a finite checklist. Include scheduled jobs that run only monthly. A rename can sit unnoticed until close day if testing covers only the daily workload.
Do not alter encrypted or vendor owned modules blindly. Check support boundaries and obtain the source definition through the proper owner. The database catalog cannot replace source control or deployment records when an object definition is unavailable.
SELECT OBJECT_SCHEMA_NAME(object_id) AS schema_name,
OBJECT_NAME(object_id) AS object_name
FROM sys.sql_modules
WHERE definition LIKE N'%OldCustomerCode%'
ORDER BY schema_name, object_name;Plan a Compatibility Window if Needed
If application releases cannot happen at the same time, expose the old name through a view or an explicit alias while moving consumers. A view can present both names temporarily, but duplicate columns can confuse SELECT * clients. Prefer a deliberate versioned contract when the public interface has many users.
For writes, a compatibility layer needs more care. An alias in a SELECT does not make old INSERT or UPDATE statements work against the renamed base table. Plan application changes or a supported write interface before cutover. Test both read and write paths.
I prefer a short, documented compatibility period with a removal date. Leaving two names forever makes the data model harder to understand. The old name should remain only while a known consumer still needs it.

Renaming a Column With sp_rename in a Controlled Window
sp_rename changes the column name in the table metadata. It does not rewrite every procedure, view, report, or application query that refers to the old name. Run it only after the consumer inventory and replacement definitions are ready. Take the normal backup or deployment restore point first.
Use a three-part object name of schema, table, and column, and specify COLUMN. Review computed columns, constraints, indexes, and schema bound objects that can affect the operation. Test the exact script on a representative copy before production.
I check that the new name is not already used and that the old name exists in the intended table. Those simple preflight checks prevent a script from targeting the wrong database or schema. The command is short. The preparation is the real work.
SELECT c.name
FROM sys.columns AS c
WHERE c.object_id = OBJECT_ID(N'dbo.Customer')
AND c.name IN (N'OldCustomerCode', N'CustomerCode');
EXEC sys.sp_rename
@objname = N'dbo.Customer.OldCustomerCode',
@newname = N'CustomerCode',
@objtype = N'COLUMN';Refresh Views and Update Modules
Update module definitions that explicitly use the old name. For a non-schema-bound view whose metadata needs refreshing, use sp_refreshview after the definition is corrected. sp_refreshsqlmodule can refresh metadata for supported non-schema-bound modules. Refreshing metadata does not fix a stale name inside the SQL text.
Schema bound views and indexed views need a planned alteration path. Check dependencies before the rename and rebuild or alter objects in a safe order. A view that uses SELECT * can retain stale metadata until refreshed, which creates subtle results even if a simple SELECT appears to work.
I run compilation and focused tests for each changed module. A procedure can compile yet fail on an untested branch of dynamic SQL. Execute representative paths with realistic parameters. The inventory should record which branches were exercised.
EXEC sys.sp_refreshview @viewname = N'dbo.vCustomer';
EXEC sys.sp_refreshsqlmodule @name = N'dbo.GetCustomer';Test Reports, Jobs, and Client SQL After Renaming a Column
Run report datasets that reference the column. Check SSIS mappings, Power BI refresh, SQL Agent steps, and application queries. A stored procedure test cannot prove a report expression still recognizes its field. Test through each consumer’s actual connection identity and deployment version.
Include negative and edge paths. A search screen can select the field only when a filter is supplied. A monthly export can use a different query from the main report. I ask owners to verify the operations they depend on, not only the first screen that opens.
Watch errors after release for the old name. Search logs and Query Store text where available. A late consumer can surface after the change window. Keep the compatibility or rollback plan ready until the operating cycle has covered the less frequent paths.
SELECT name, modify_date
FROM sys.objects
WHERE name IN (N'vCustomer', N'GetCustomer')
ORDER BY name;Close the Rename With Evidence
Re-run dependency and text searches. Review remaining matches, including comments and intentional compatibility aliases. Confirm the old name is absent from the base table and the new name has the expected data type and nullability. Compare representative query results before and after.
Keep the change inventory and test results with the deployment record. If an error appears later, the team can see which consumers were updated and which still relied on a temporary alias. That is much faster than repeating the original search under pressure.
Safely renaming a column changes a contract across database objects and clients. sp_rename performs one metadata operation. The rest of the work is finding, updating, and testing every place the name carries meaning.
Which monthly report or scheduled export still names the old column after the main application tests pass?
Related reading on this blog: How to Rename a Column Name or Table Name and FIX: sp_rename error Msg 15225: No item by the name of '%s' could be found in the current database.

A column rename is not one metadata command, it is a coordinated change to every consumer.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.





3 Comments. Leave new
This has a limitation. It wont return any dependency where object has been used inside a dynamic sql string
see this small example
CREATE PROCEDURE proctest1
AS
EXEC(‘SELECT * FROM YourTable’)
GO
CREATE PROCEDURE proctest1
AS
SELECT * FROM YourTable
GO
–finding dependency using two conventional methods
sp_depends ‘YourTable’
SELECT ‘EXEC sp_helptext [‘ + referencing_schema_name + ‘.’ + referencing_entity_name + ‘]’
FROM sys.dm_sql_referencing_entities(‘YourTable’,’OBJECT’)
both of the above doesnt return proctest as table was used inside dynamic string in it. In such cases I rely upon below query
select definition from sys.sql_modules where definition like ‘% Employee%’
and I’ve blogged about that as well here
I need to search all content of my database object(only SPs) but the challenge is i have to ignore the commented part??
The same thing i have to do for almost 60 DBs and each DB approx contain at least 300 SPs.
Any good way to do this??
Hi PinalDave –
In your previous post the “Alter to” is not available in the picture. Do you know why this is grayed out, or not available as an option?
I thought it was permissions, but gave myself db_owner of the database and the resulting menu still appears the same.
Any ideas how to script the objects as “Alter to”?
Any feedback is much appreciated.
Thank you,
Eric