Home Quartz SQL Alter Column Name



SQL Alter Column Name
Posted on: April 18, 2011 at 12:00 AM
sql alter column name

SQL Alter Column Name

     

Alter Column Name in SQL is used to change or modify the name of column in a table.

Understand with Example

The Tutorial explain you a simple example on SQL Alter Column Name. In this Example, create a table 'Stu_Table' using create statement. The insert into help you to add the records into created table 'Stu_Table'. The select statement retain you the records from table 'Stu_Table'. The ALTER  table statement in SQL is used to modify the table 'Stu_Table'.

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

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

Syntax

The ALTER  table statement in SQL is used to modify the table 'Stu_Table' and change keyword change the name of field to new  name of field. The syntax used for Alter Table is given below: 

Alter table table_name change old_column_name  new_column_name type size   

Query

The Alter Table alter the table 'Stu_Table'. The change keyword change the column name of  Stu_Id to Id in table 'Stu_Table'.

Alter table Stu_Table change Stu_Id Id varchar(10)

Stu_Table

+--------+----------+-----------+
| Id     | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Rakesh   | 10        |
| 4      | Bhanu    | 10        |
| 5      | Santosh  | 10        | 
+--------+----------+-----------+

Related Tags for SQL Alter Column Name:


More Tutorials from this section

Ask Questions?    Discuss: SQL Alter Column Name  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.