Database

Alter Table Statement in MySQL : How to Rename Column in Table

In this tutorial I will show you how to rename column in a table.

RENAME COLUMN IN A TABLE

Syntax

Follow the below syntax to rename a column in a table using MySQL Alter Table Statement.

ALTER TABLE table_name
  CHANGE COLUMN old_name new_name 
    column_definition
    [ FIRST | AFTER column_name ]

Where;

  • table_name : The name of the table to modify.
  • old_name : The column to rename.
  • new_name : New name for the column.
  • column_definition : The datatype and definition of the column such as NULL OR NOT NULL etc. You must specify the column definition when renaming the column, even if it does not change.
  • FIRST | AFTER column_name : Optional. It tells MySQL where in the table to position the column, if you wish to change its position.

Example

Let’s see how we can rename a column in a MySQL table using Alter Table Statement.

ALTER TABLE contacts
  CHANGE COLUMN contact_type ctype
    varchar(20) NOT NULL;

In the above example MySQL AFTER TABLE example will rename the column called contact_type to ctype. The column will be defined as a varchar(20) NOT NULL column.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment