add column in table

How To Add Column in a Table in SQL

Today, we are going to learn how to add a column in a table using SQL (structured query language). The query you will learn here is ALTER TABLE table ADD COLUMN column INT(10).

After the column name, you need to define its data type. You may define it according to your needs.

If you store integer number in the column then the data type will be INT(20) and if you store strings then data type – VARCHAR(50). in its parenthesis, give the length.


Table of Contents


The SQL query to add a single column in a table

ALTER TABLE admission ADD COLUMN fee INT(10);

Add single column starting (FIRST) in table

ALTER TABLE result ADD students VARCHAR(10) FIRST;

Or

ALTER TABLE result ADD COLUMN students VARCHAR(10) FIRST;

The SQL query to add multiple columns

ALTER TABLE result ADD COLUMN students VARCHAR(10), ADD aaa VARCHAR(10);

Or

ALTER TABLE result ADD students VARCHAR(10), ADD aaa VARCHAR(10);

Add multiples columns in starting of the table

ALTER TABLE result ADD COLUMN students VARCHAR(10) FIRST, ADD aaa VARCHAR(10) FIRST;

Or

ALTER TABLE result ADD COLUMN students VARCHAR(10) FIRST, ADD aaa VARCHAR(10) AFTER students;

Add multiple columns after a specific column

ALTER TABLE result ADD class VARCHAR(10) AFTER students, ADD village VARCHAR(10) AFTER class;

Leave a Comment