SQL Alter Table Add Column

SQL Alter Table Add Column

What is SQL?

SQL stands for Structured Query Language. Just like Python, Java, and PHP are programming languages, SQL is a database language to interact with databases.

A programming language can’t directly interact with a database, so SQL language acts as a messenger that accesses and manipulate databases.

A database is the collection of organized data that is stored either on the local system or on the internet. Storing data in a database makes it easier to access and manipulate it. Any dynamic website uses a database to store data at the backend. For example, when you post anything on social media, all the alphanumeric data gets stored in the database.

You can read more about SQL here on this page.

In SQL, Alter is a Data Definition Language (DDL) that is used to add, delete, or modify columns in an existing table. If an existing table has some constraints, Alter commands can also be used to change it.

In this post, we will add a new column in a SQL table using Alter command.

We will first create a table named ’employee’ using SQL query then we will further add a new column(s) in it using Alter command.

Creating a Table in SQL

create table employee(
          id int,
          name varchar(10)
          address varchar(255)
);

Adding a new column in the above table

alter table employee add country varchar(10);

Adding multiple new columns in the table

alter table employee
add column phone VARCHAR(100),
add column PIN INT(10)

SQL QUERY to Insert Multiple Rows in the Table