How can we change the name and data type of a column of a
table?

Answer Posted / nithya

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

Is This Answer Correct ?    9 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the difference between and myisam and innodb?

522


What is mysql default database?

488


What is mysql enterprise edition?

466


What is sqlyog?

622


Is mysql free for commercial use?

482






change column name and make a unique column so we get no dupes.

508


How to control the max size of a heap table?

559


What are date and time data types in mysql?

526


How do I show columns in mysql?

491


What is the maximum number of columns per table?

493


What is the limit of mysql database?

501


How can you import tables from a sql file into a database by using the mysql client?

550


How to create trigger in mysql phpmyadmin?

526


What is mysql root?

499


How can you change the password of a mysql user?

506