SQL Alter Column Size
Alter Column Size modify the Column Size. The SQL Alter Column Size is used when you want to change the data type size.
Understand with Example
The Tutorial brings you an illustrative example from SQL Alter Column Size. In this example we create a Table 'Stu_Table' with the help of create statement. The insert into adds the records or rows into the table 'Stu_Table'. The Describe 'Stu_Table' display the Table attribute like field name, field size ,null etc.
.The alter statement modify and change the Table 'Stu_Table'. Now you want to change the size of data type of your field. In this case, we modify the size of Stu_Id,whose size is '2' to '100'.The MODIFY keyword in SQL Query is used to modify the data type size.Again,Describe Table show you the modified information upon on table attribute like column name, data type, null ,etc.
Create Table Stu_Table
create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15), Stu_Class varchar(10)) |
Insert data into Stu_Table
insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal'); insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay'); insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh'); insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu'); insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh'); |
Stu_Table
+--------+----------+-----------+ | Stu_Id | Stu_Name | Stu_Class | +--------+----------+-----------+ | 1 | Komal | 10 | | 2 | Ajay | 10 | | 3 | Rakesh | 10 | | 4 | Bhanu | 10 | | 5 | Santosh | 10 | +--------+----------+-----------+ |
Describe Stu_Table
+-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | Stu_Id | varchar(2) | YES | | | | | Stu_Name | varchar(15) | YES | | | | | Stu_Class | varchar(10) | YES | | | | +-----------+-------------+------+-----+---------+-------+ |
Alter Column Size Query
ALTER TABLE Stu_Table MODIFY Stu_Id varchar(100) |
Describe Stu_Table
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | Stu_Id | varchar(100) | YES | | | | | Stu_Name | varchar(15) | YES | | | | | Stu_Class | varchar(10) | YES | | | | +-----------+--------------+------+-----+---------+-------+ |