How to Add Multiple Columns in SQL?

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

As a database developer, you need to add columns to the existing table. Adding a column using SQL server management studio might be feasible for smaller tables but when it comes to larger tables, you'd need a simpler way to modify and add multiple columns of SQL.

You can add multiple columns in SQL in many ways. For example, to add multiple columns in SQL, you can use the ALTER TABLE ADD statement in SQL. This statement can also be used to modify a column, drop a column, or rename a column. There are different ways in which you can add multiple columns in SQL. There are different database systems and there is a variety of ways in which you can add multiple columns of SQL, which you'll study in this article.

ALTER TABLE Statement

After the creation of the table, it may happen that you forgot to add an important column to the table that you need. In this situation, you can use the ALTER TABLE ADD statement to add multiple columns in SQL. To add multiple columns SQL, specify multiple columns to add after the ADD keyword and separate each column that you want to add using a comma.

In this article, you'll learn about how to add multiple columns of SQL using the ALTER TABLE statement. You can also modify or delete the specific columns using the ALTER TABLE statement.

Let's look at the syntax of the ALTER TABLE statement and see how it can be used to add multiple columns in SQL.

The above-given syntax is used to add a column to the table and you can also add multiple columns in SQL using the ALTER TABLE statement and the syntax of which is discussed in this article.

Now, let's see how the ALTER TABLE statement can be used to add a new column in SQL.

As shown in the above query, the ALTER TABLE ADD statement is used to add a new column i.e. prdct_description to the Products table.

Creating a Table

Let's create a Sales table. The below-given query is used to create the Sales table.

The output of the above SQL query is shown below:

Now, if you want to add a new column to the table you can use the ALTER TABLE ADD COLUMN statement. Using this statement you can add as many columns as you want to add to the table that is already created. To add a new column of the name prdct_sales, the below alter table statement is used.

Now, after executing the above SQL query, the result will look like this:

Output:

As you can see in the above result, the new column i.e. prdct_sales is added to the Sales table. The values to the newly added column are not provided hence the NULL is displayed in the result.

Add Multiple Columns in SQL

You can add multiple columns in a table in SQL using the ALTER TABLE statement.

The syntax to add multiple columns SQL is given below:

As shown in the above syntax, you can also add multiple columns of SQL using the ALTER TABLE statement. As specified above, you can add multiple columns SQL by using the ADD keyword and separate each column using a comma. The above example adds n columns i.e. column1, column2, and so on, to the table_name table.

Let's take an example to see how you can add multiple columns of SQL using the ALTER TABLE statement.

SQL ADD COLUMN Clause with Examples

You can also use the ADD COLUMN clause to add columns to a table in SQL.

The syntax of the ADD COLUMN clause is given below and is explained with examples.

Syntax:

Example:

Let's create a table named Teachers. The below query is used to create the table.

Now, if you want to add new columns, for example, fees, address, and teacher_account, you can use the below query:

Thus, the ALTER TABLE ADD COLUMN statement can be used to add one or more columns to the tables in SQL.

SQL ADD COLUMN Statement in Some Common Database Systems

In this section, you are going to learn about different ways in which you can use the SQL ADD COLUMN statement according to the various database systems present out there.

1. PostgreSQL

Adding one column to an existing table in PostgreSQL:

Adding multiple columns to an existing table in PostgreSQL:

2. MySQL

Adding one column to an existing table in MySQL:

Adding multiple columns to an existing table in MySQL:

3. Oracle

Adding one column to an existing table in Oracle:

Adding multiple columns to an existing table in Oracle:

4. SQL Server

Adding one column to an existing table in SQL Server:

Adding multiple columns to an existing table in SQL Server:

5. SQLite

Adding one column to an existing table in SQL Server:

Adding multiple columns to an existing table in SQLite:

You cannot add multiple columns to an existing table using at once in SQLite as it does not support adding multiple tables using a single statement. Instead, you can execute multiple ALTER ADD COLUMN statements.

6. DB2

Adding one column to an existing table in SQL Server:

Adding multiple columns to an existing table in DB2:

Learn more

Conclusion

  • In this article, you learned about the ALTER TABLE ADD COLUMN statement to add one or more columns to an existing table.
  • To add multiple columns SQL, specify multiple columns to add after the ADD keyword and separate each column that you want to add using a comma.
  • You can also modify or delete the specific columns using the ALTER TABLE statement.
  • You can also use the ADD COLUMN clause to add columns to a table in SQL.