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
What is unsigned int in mysql?
What is the difference between is null & is not null?
What is timestamp in mysql?
How can I see all mysql databases?
What is blob datatype in mysql?
What is the purpose of using ifnull() function?
Table - Products has number of products as below Productid ProductName 1 iPhone 2 iPad 3 BlackBerry Table - SalesPersonProduct has the below records Salespersonid productid S1 1 S1 2 S1 3 S2 1 S3 2 Write a SQL query that returns the total number of sold products
What is the difference between mysql_connect and mysqli_connect?
Is mysql a database?
How to delete an existing column in a table?
How do I download mysql?
What are the 3 main types of search queries?
Is null in mysql?
Why mysql is so popular?
How do I run mysql?