| Question |
How can we change the name and data type of a column of a
table? |
|
Question Submitted By :: Pranab |
|
I also faced this Question!! |
Rank |
Answer Posted By |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 1 |
To Change DataType of Column:
Sy: Alter Table <Table Name> Modify <ColumnName> <DataType>;
Ex: Alter Table Test Modify EmpId varchar(5);
|
| M. Ravindar |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 2 |
To Change Name of Column:
Sy: Alter Table <Table Name> Change <Old ColumnName> <New
ColumnName>;
Ex: Alter Table Test Change EmpId EID varchar(5);
|
| M. Ravindar |
| |
|
|
| |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 3 |
ALTER TABLE `<tablename>` CHANGE `<old column>` `<new
column>` new datatype( length )
|
| Abhishek |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 4 |
Hi This is yOgEsH....!!
By this query we can change the data type of particular column :
ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);
|
| Yogesh Verma |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 5 |
o Change DataType of Column:
Sy: Alter Table <Table Name> Modify <ColumnName> <DataType>;
Ex: Alter Table Test Modify EmpId varchar(5);
|
| Ashish |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 6 |
To change the name of the column:
ALTER TABLE TABLENAME RENAME COLUMN OLD_COLUMN_NAME TO
NEW_COLUMN_NAME;
eg: alter table employee rename column emp_name to ename;
To change the datatype of a column:
ALTER TABLE TABLENAME MODIGY COLUMN_NAME NEW_DATA_TYPE;
eg: alter table employee modify ename varchar(50);
NOTE: u cannot modify column of a datatype from larger value
to smaller value.U can do it only if there is no data in ur
column.
eg: alter table employ_detail modify emp_addr varchar(5);
ORA-01441: cannot decrease column length because some value
is too big
alter table employ_detail modify emp_id number(2)
ORA-01440: column to be modified must be empty to decrease
precision or scale
|
| Nithya |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 7 |
excuse mr pls
ALTER TABLE products ALTER COLUMN price TYPE numeric
(10,2);
uyah nanhi vhalta hai
|
| Szsad |
| |
|
Re: How can we change the name and data type of a column of a
table? |
Answer
# 8 |
to add new columns in databases
alter table <table name> add column <column name> datatype;
|
| Aftab Alam |
| |
|
|
|
|
|
| |