SQL Alter Column

SQL Alter Column modifies the existing table and add a column.

SQL Alter Column

SQL Alter Column

     

SQL Alter Column modifies the existing table and add a column.

Understand with Example

The Tutorial illustrate an example from 'SQL Alter Column'. To understand and grasp this example, we create a table 'Stu_Table'. The create table statement construct a table 'Stu_Table' with field attribute and data type specified in Query respectively. 

Create Table Stu_Table

create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class  varchar(10))

Insert data into Stu_Table

The insert into insert the records or row values into table 'Stu_Table'.

insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',10);
insert into Stu_Table values(4,'Bhanu',10);
insert into Stu_Table values(5,'Santosh',10);
insert into Stu_Table values(6,'Tanuj',10);

Stu_Table

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
6 Tanuj 10

SQL ALTER Syntax

The SQL ALTER Syntax is used to modify the table and add a column name that you want to add and its data type.

ALTER TABLE table_name
ADD column_name column-definition

SQL ALTER Query

The given below Query alter a table 'Stu_Table' and add keyword add a column Stu_Class whose data type is varchar type.

Alter Table Stu_Table add Stu_Class varchar(10)

View data  Stu_Table

Stu_Id Stu_Name Stu_Class
1 Komal NULL
2 Ajay NULL
3 Rakesh NULL
4 Bhanu NULL
5 Santosh NULL