Database

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

modify-column
mm
Written by Santosh Prasad

In this article I will show you how to add modify columns in table.

MODIFY COLUMN IN TABLE

Syntax

Follow the below syntax to modify column in the table.

ALTER TABLE table_name
  MODIFY column_name column_definition
    [ FIRST | AFTER column_name ];

Where;

  • table_name : Name of the table to modify.
  • new_column_name : Name of the new column to modify in the table.
  • column_definition : Data type and definition of the column such as NULL or NOT NULL.
  • FIRST | AFTER column_name : This is optional, it tells where in the table to create the column. If this is not mentioned by default new column will be added to the end of the table.

Example

Let’s see how to modify column in a MySQL table using the Alter Table statement.

ALTER TABLE contacts
  MODIFY last_name varchar(50) NULL;

In the above MySQL ALTER TABLE example it will modify the column called last_name to be a data type of varchar(50) and force the column to allow NULL values.

Thank you! for visiting Look Linux.

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 Look Linux 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