Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL - Getting Started
  • What is SQL
  • Create Table
  • ALTER TABLE Statements
  • Rename Columns
  • Modify Column Type
  • Drop Columns
  • Rename Tables
  • Drop Tables
  • Insert Statement
  • Update Statement
  • Delete Statement
  • Truncate Statement
  • Merge Statement
  • Null Value
  • Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL - Inner Join
  • SQL - Left Join
  • SQL - Right Join
  • SQL - Full Join
  • SQL - BETWEEN
  • SQL - IN
  • SQL - LIKE
  • SQL - INTERSECT
  • SQL - MINUS
  • SQL - UNION
  • SQL - UNION ALL
  • SQL - DISTINCT
  • SQL - ANY, SOME
  • SQL - ALL
  • SQL - AVG()
  • SQL - COUNT()
  • SQL - MAX()
  • SQL - MIN()
  • SQL - SUM()
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

ALTER TABLE RENAME - Rename Columns

The ALTER command is a DDL command to modify the structure of existing tables in the database by adding, modifying, renaming, or dropping columns and constraints. Use the ALTER TABLE RENAME command to rename column names.

Syntax:

ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;

For the demo purpose, consider the following Employee table.

EmpIdFirstNameLastNameEmailPhoneNoSalaryAddressPinCode
        

The following SQL script will rename PinCode to ZipCode in the Employee table in Oracle, MySQL, PostgreSQL, SQLite database.

SQL Script: Rename Column
ALTER TABLE Employee RENAME COLUMN PinCode TO ZipCode;

Use the built-in procedure sp_rename to changes the name of a user-created object in the database such as tables, indexes, columns, and alias data types in MS SQL Server. The following renames PinCode to ZipCode.

SQL Script: Rename Column in SQL Server
EXEC sp_rename 'Employee.PinCode', 'Employee.ZipCode';

The above ALTER TABLE RENAME SQL script will change the Employee table as below.

EmpIdFirstNameLastNameEmailPhoneNoSalaryAddressZipCode
        

You cannot rename muliple columns in a single rename statement. Use different rename script to rename multiple columns.

The following RENAME script renames multiple column names.

SQL Script: Rename Multiple Columns
ALTER TABLE Employee 
RENAME COLUMN FirstName TO First_Name;

ALTER TABLE Employee 
RENAME COLUMN PhoneNo TO Phone;
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.