DEV Community

Cover image for How To Add A New Column In An Existing Table Using MySQL
Md. Fahim Bin Amin
Md. Fahim Bin Amin

Posted on

2

How To Add A New Column In An Existing Table Using MySQL

For adding a column (attribute) to an existing table, we use the MODIFY statement in MySQL.

For example, suppose that I have a table named student. The student table contains 3 columns (attributes) named name, id and cgpa. Now I want to add one more column named phone_number there.

Then the MySQL command would be:

ALTER TABLE student ADD phone_number VARCHAR(12);
Enter fullscreen mode Exit fullscreen mode

Now let me explain each keyword. As I want to alter a table that is already been created, I used the ALTER keyword. Then the question comes which thing I want to alter; is it a table or database or anything else? The answer is I want to alter a particular table.

Therefore I used ALTER TABLE. A database can have multiple tables in it. I need to spcify the exact table where I want to make the alteration. Therefore, I stated the table name there. Then comes the part exactly which type of alteration I want to apply.

As I want to add a new column, I have stated that in my command. Then I stated my new attribute (column) name and the data type with it.

After finishing the statement, I used a semicolon to specify that the statement is finished.

That is how the query command works!

๐Ÿ“น If you are comfortable with a step by step video tutorial, then I have already created one video for all of you!

If you want to follow me then you can follow me on Twitter and GitHub.
Also, make sure to endorse me on relevant skills in LinkedIn.

If you like to watch programming related content regularly, then check out my YouTube channel.

Have a good day! ๐Ÿ˜Š

Cover: Photo by Caspar Camille Rubin on Unsplash

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry ๐Ÿ‘€

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more โ†’

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay