Skip to content
Fix Code Error

Rename column SQL Server 2008

March 13, 2021 by Code Error
Posted By: Anonymous

I am using SQL Server 2008 and Navicat. I need to rename a column in a table using SQL.

ALTER TABLE table_name RENAME COLUMN old_name to new_name;

This statement doesn’t work.

Solution

Use sp_rename

EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN'

See: SQL SERVER – How to Rename a Column Name or Table Name

Documentation: sp_rename (Transact-SQL)

For your case it would be:

EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN'

Remember to use single quotes to enclose your values.

Answered By: Anonymous

Related Articles

  • What's the difference between eval, exec, and compile?
  • How can I get column names from a table in SQL Server?
  • How do I include certain conditions in SQL Count
  • How do I rename both a Git local and remote branch name?
  • An Authentication object was not found in the…
  • Python copy files to a new directory and rename if…
  • Obtain most recent value for based on index in a…
  • Log record changes in SQL server in an audit table
  • How do I fetch multiple columns for use in a cursor loop?
  • JSON Dump a string surrounded by single quotes and…
  • Find a string by searching all tables in SQL Server…
  • Drop all the tables, stored procedures, triggers,…
  • Search all tables, all columns for a specific value…
  • Find a value anywhere in a database
  • Search for one value in any column of any table…
  • Rename a column in MySQL
  • Jetpack Compose and Hilt Conflict
  • SMTP error 554
  • Invalid column name when using dynamic SQL
  • Difference between single and double quotes in Bash
  • How can I rename a conda environment?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • YAML: Do I need quotes for strings in YAML?
  • Insert into not inserting for mysql
  • Changing the maximum length of a varchar column?
  • My quick Sort Function in Kotlin give the wrong output back
  • DROP Constraint without knowing the name
  • How to DROP multiple columns with a single ALTER…
  • Executing T-SQL query from table
  • How do I add a auto_increment primary key in SQL…
  • Execution failed for task…
  • Struggling with a nested where, group by and min/max in SQL
  • Best way to do multi-row insert in Oracle?
  • Dynamic SQL executed inside a stored procedure in a…
  • SQL split values to multiple rows
  • How to set variables in HIVE scripts
  • When to use single quotes, double quotes, and…
  • What are the uses of the exec command in shell scripts?
  • ASP.Net Core Razor Page - Pass Selected Name From…
  • How do I rename a column in a SQLite database table?
  • Removing double quotes from variables in batch file…
  • Generate SQL Create Scripts for existing tables with Query
  • how to show progress bar(circle) in an activity…
  • T-SQL: Export to new Excel file
  • Android- Error:Execution failed for task…
  • What are the undocumented features and limitations…
  • How can I parse a CSV string with JavaScript, which…
  • Change type of varchar field to integer: "cannot be…
  • How do you rename a MongoDB database?
  • Persistent invalid graphics state error when using ggplot2
  • Adding an identity to an existing column
  • How to change a table name using an SQL query?
  • Delete columns from multiple tables
  • java.sql.SQLException: - ORA-01000: maximum open…
  • R Shiny Line Plot with Multiple Lines
  • Type datetime for input parameter in procedure
  • Backbone routing regex
  • How to rename a table in SQL Server?
  • How to take backup of a single table in a MySQL database?
  • Disable all table constraints in Oracle
  • data.table vs dplyr: can one do something well the…
  • Changing a specific column name in pandas DataFrame
  • Vue routes doesn't work
  • including parameters in OPENQUERY
  • extensiv function in Java
  • SQL Client for Mac OS X that works with MS SQL Server
  • MySQL: ALTER TABLE if column not exists
  • add column to mysql table if it does not exist
  • What is the difference between single-quoted and…
  • Why does find -exec mv {} ./target/ + not work?
  • How to check if a table exists in a given schema
  • Getting Checkbox Value in ASP.NET MVC 4
  • jQuery.parseJSON throws “Invalid JSON” error due to…
  • Change all bit columns to int with default value NULL
  • Android Room - Issue with query with WHERE condition
  • ALTER DATABASE failed because a lock could not be…
  • How to find out what is locking my tables?
  • Python subprocess with apostrophes, removes them
  • How to convert an entire MySQL database characterset…
  • insert a NOT NULL column to an existing table
  • Problems with local variable scope. How to solve it?
  • MySQL 1062 - Duplicate entry '0' for key 'PRIMARY'
  • Call to a member function…
  • What would be the type of the object returned by the…
  • Sort table rows In Bootstrap
  • Retrieving a list of Dictionaries from Nested…
  • Rails: How can I rename a database column in a Ruby…
  • How to terminate SQL statements when using DEFAULT…
  • CSS Input with width: 100% goes outside parent's bound
  • How do I use the CONCAT function in SQL Server 2008 R2?
  • SQL query return data from multiple tables
  • Postgresql : syntax error at or near "-"
  • Multiple separate IF conditions in SQL Server
  • SQL syntax error when executing MySQL script using…
  • Insert new column into table in sqlite?
  • What is the difference between single and double…
  • Bash: Echoing a echo command with a variable in bash
  • What does "Fatal error: Unexpectedly found nil while…
  • Add new column with foreign key constraint in one command
  • Is there a way to retrieve the view definition from…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Finding the average of a list

Next Post:

How do I copy an object in Java?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error