The statement: Simple renaming column names were expected.
-- Add ALTER COLUMN commands before renaming to ensure columns are ready for renaming
ALTER TABLE [dbo].[FY_22_23] ALTER COLUMN [CNo] VARCHAR(50);
-- Now rename columns using sp_rename
EXEC sp_rename '[dbo].[FY_22_23].[CNo]', '[CNo#]', 'COLUMN';
returns this error:
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 247 [Batch
Start Line 0] Either the parameter @objname is ambiguous or the
claimed @objtype (COLUMN) is wrong.
Completion time: 2024-09-25T10:38:05.0998645+05:30
Agnel Salve is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
10
Just do it. Already tested in my machine.
EXEC sp_rename 'dbo.FY_22_23.CNo', 'CNo#', [COLUMN]
Abu Ben Reaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
Please ensure that the object name includes the schema, table, and column names.
EXEC sp_rename 'dbo.MyTable.OldColumnName', 'NewColumnName', 'COLUMN';
Puneet Kukreja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
CREATE TABLE EMPLOYEE (
empId int,
name varchar(15),
dept varchar(10)
);
INSERT INTO EMPLOYEE(empId,name,dept) VALUES (1, 'Clark', 'Sales');
INSERT INTO EMPLOYEE(empId,name,dept) VALUES (2, 'Dave', 'Accounting');
-- EXEC sp_RENAME 'TableName.OLDCloumnName','New Column Name','COLUMN'
EXEC sp_RENAME 'EMPLOYEE.Name', 'EMPName' , 'COLUMN'
SELECT * FROM EMPLOYEE;
GO
Result :
empId EMPName dept
----------- --------------- ----------
1 Clark Sales
2 Dave Accounting
1