i2tutorials

SQL ALTER TABLE

SQL ALTER TABLE

In this tutorial we will discuss, How can we use the alter command to alter the table? 

Alteration to the table is nothing but modifying the table structure. So you need to understand we did not enter any data till now. We have just created the structure of the table. So this is the structure of the table.

As we have already entered all these data in the create table, with the help of this data, we will alter the table in such a way that, we can even see the table which we need. Now that I wanted to add a mobile number or contact address, as a column name.

Hence you need to mention add command. So we are going to add what we need, so I wanted to add the mobile no.

Syntax:

Alter table table_name 
Add column_name data_type constraint;

Example:

alter table users add ( 
mobile varchar2(20)
)

Select * from users;

Output:

Where you can see user ID, username, age, email, and mobile. So the mobile is the new column name which was introduced using the alter command.  You can just give multiple columns at a time to add to the existing table, which is called users.

Exit mobile version