Add column to an existing table using SQL alter table statement Explained in Detail
This is the second tutorial in the alter table series.
In the last tutorial we saw How to rename a table using ALTER TABLE statement.
Has it ever happened with you that after creating a table, you realized that you need to add another column to it? It generally happens with me.
The first thing which comes into the mind in this scenario is to Drop the table and recreate it with that extra column. But what if your table has a data which you cannot compromise. Means dropping a table is not the solution here.
Don’t worry there is a solution for this problem.
It is possible to add a column to an existing table using
ALTER TABLE statement. By Using ALTER TABLE statement you
can add one or more than one columns to an existing table.
Let’s see how.
In the previous tutorial we have created a very simple table by the name of Test. Test table has only one column test_name.
Let’s see how to add test_id column to Test table using alter
Hope syntax is clear. So now let’s write a SQL query for adding test_id
column to Test table.
So this is it folks. Hope you find this article useful. Stay tuned for more such tutorials. You can also check out my YouTube channel for more SQL tutorial videos. Please share it with your friends and help me spread the word. Thanks!
You can DOWNLOAD SQL script and presentation used in the Video and in this article.