Home Sql SQL Alter Column Size
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

SQL Alter Column Size

Advertisement
Alter Column Size modify the Column Size. The SQL Alter Column Size is used when you want to change the data type size.

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  |     |         |       |
+-----------+--------------+------+-----+---------+-------+
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Ask Questions?    Discuss: SQL Alter Column Size   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Anuja
January 12, 2012
change size of column when index is created.

Hi. I am using MS Sql database. I have a column of datatype nvarchar(255). I want to increase the
sahil
February 15, 2012
not work in mssql

ALTER TABLE Stu_Table MODIFY Stu_Id varchar(100) this is query not work in mssql. please check your query. thanks
ramesh
July 23, 2012
sql query

I need to increase column size varchar(78) to varchar(250)
ravichandra
September 25, 2012
alter

modify will not work in SQL Find the example given below "ALTER TABLE Stu_Table alter column Stu_Id varchar(100)"
DMCA.com