In this post we will discuss how we can rename a table name or a column name in sql server 2008 through sql query.
Also you can check out my previous posts on:
- Add Primary Key Constraint to existing table in sql server 2008
- Asp.Net MVC4 Controller class example
- How to give Tooltips in WPF in Asp.Net?
We can rename by using the sp_rename stored procedure.
- sp_rename changes the name of the user defined objects like table, index, column, alias data type, or Microsoft .NET Framework common language runtime (CLR) user-defined type.
- If the return value is 0 (Zero) means success and if a nonzero number means its a failure.
- But it is not recommended to rename stored procedures, triggers, user-defined functions, or views, instead we should drop the object and re-create it with the new name.
Rename a Table:
You can rename a table by using the below query:
sp_rename Employees, EmployeesInfo
Here Employees is the old name and EmployeesInfo is the new name.
Rename a Column:
Below is the command to rename a column:
sp_rename 'Employees.Name', 'EmployeeName', 'COLUMN';
Here Employees is the table name, Name is the old column name and EmployeeName is the new column name.
Hope this will be helpful to you.
Also you can check out my previous posts on:
- Add Primary Key Constraint to existing table in sql server 2008
- Asp.Net MVC4 Controller class example
- How to give Tooltips in WPF in Asp.Net?
We can rename by using the sp_rename stored procedure.
- sp_rename changes the name of the user defined objects like table, index, column, alias data type, or Microsoft .NET Framework common language runtime (CLR) user-defined type.
- If the return value is 0 (Zero) means success and if a nonzero number means its a failure.
- But it is not recommended to rename stored procedures, triggers, user-defined functions, or views, instead we should drop the object and re-create it with the new name.
Rename a Table:
You can rename a table by using the below query:
sp_rename Employees, EmployeesInfo
Here Employees is the old name and EmployeesInfo is the new name.
Rename a Column:
Below is the command to rename a column:
sp_rename 'Employees.Name', 'EmployeeName', 'COLUMN';
Here Employees is the table name, Name is the old column name and EmployeeName is the new column name.
Hope this will be helpful to you.