How do I rename a column in a database table using SQL?

MetroidFan2002 picture MetroidFan2002 · Oct 6, 2008 · Viewed 516.7k times · Source

If I wish to simply rename a column (not change its type or constraints, just its name) in an SQL database using SQL, how do I do that? Or is it not possible?

This is for any database claiming to support SQL, I'm simply looking for an SQL-specific query that will work regardless of actual database implementation.

Answer

Galwegian picture Galwegian · Oct 6, 2008

Specifically for SQL Server, use sp_rename

USE AdventureWorks;
GO
EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';
GO