How to rename an existing column with the "sp_rename" stored procedure in MS SQL Server?
Submitted by: AdministratorIf you have an existing column in a table and you want to change the column name, you can use the "sp_rename ... 'COLUMN'" stored procedure. "sp_rename" allows you to change names of COLUMN, DATABASE, INDEX, USERDATATYPE, and OBJECT. The tutorial example below shows you how to rename a column:
USE master
GO
sp_rename 'tip.subject', 'title', 'COLUMN'
GO
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 213
Either the parameter @objname is ambiguous or the claimed
@objtype (COLUMN) is wrong.
USE GlobalGuideLineDatabase
GO
sp_rename 'tip.subject', 'title', 'COLUMN'
GO
Caution: Changing any part of an object name could break
scripts and stored procedures.
SELECT id, title, description, author FROM tip
GO
id title description author
1 Learn SQL Visit www.globalguideline.com NULL
You are getting the first error because 'GlobalGuideLineDatabase' is not the current database.
Submitted by: Administrator
USE master
GO
sp_rename 'tip.subject', 'title', 'COLUMN'
GO
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 213
Either the parameter @objname is ambiguous or the claimed
@objtype (COLUMN) is wrong.
USE GlobalGuideLineDatabase
GO
sp_rename 'tip.subject', 'title', 'COLUMN'
GO
Caution: Changing any part of an object name could break
scripts and stored procedures.
SELECT id, title, description, author FROM tip
GO
id title description author
1 Learn SQL Visit www.globalguideline.com NULL
You are getting the first error because 'GlobalGuideLineDatabase' is not the current database.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | What Is a Subquery in a SELECT Query Statement in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | How To Configure ODBC DSN with Different Port Numbers? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |