To rename an existing column in a SQL Server table using sp_rename, pass the schema-qualified table and current column name as @objname, the new column name as @newname, and ‘COLUMN’ as @objtype:
SQL EXEC sp_rename @objname = N’dbo.orders.old_column_name’, @newname = N’new_column_name’, @objtype = N’COLUMN’;
- Basic Syntax and Execution Rules @objname: Format as N’schema_name.table_name.current_column_name’ (for example, N’dbo.customers.phone_no’). Note that in T-SQL, @newname is passed as just the new column identifier—do not prefix @newname with the schema or table name.
@newname: Provide only the new column name (for example, N’phone_number’). Avoid spaces or reserved words unless deliberately required.
@objtype: Always pass N’COLUMN’ when renaming a column so SQL Server does not treat @objname as a table, index, or alias.
SQL – Example: Rename customer_phone to mobile_number on dbo.customers EXEC sp_rename @objname = N’dbo.customers.customer_phone’, @newname = N’mobile_number’, @objtype = N’COLUMN’; When sp_rename succeeds, SQL Server prints a cautionary notice stating that changing part of an object’s name could break scripts and stored procedures.
- Inspecting Dependencies Before and After Renaming Renaming a column does not automatically update dependent objects such as views, stored procedures, user-defined functions, triggers, computed columns, or client queries.
Find Dependent Modules Before Renaming SQL SELECT DISTINCT OBJECT_SCHEMA_NAME(d.referencing_id) AS referencing_schema, OBJECT_NAME(d.referencing_id) AS referencing_object, o.type_desc AS object_type FROM sys.sql_expression_dependencies AS d INNER JOIN sys.objects AS o ON d.referencing_id = o.object_id WHERE d.referenced_entity_name = N’orders’ AND d.referenced_schema_name = N’dbo’ ORDER BY referencing_schema, referencing_object; Verify the Column After Renaming SQL SELECT c.name AS column_name, TYPE_NAME(c.user_type_id) AS data_type, c.max_length, c.is_nullable FROM sys.columns AS c WHERE c.object_id = OBJECT_ID(N’dbo.orders’) AND c.name = N’new_column_name’; 3. Operational Checklist Check dependent views, procedures, triggers, and application code before renaming a column in production, and update references afterward.
Avoid renaming columns actively referenced by indexes, constraints, or statistics without testing deployment scripts—metadata updates can affect dependent objects or deployments.
Never include the table or schema name in @newname; only supply the new column name.
Ensure sufficient permissions: requires ALTER on the object (or membership in db_ddladmin / db_owner / sysadmin).
