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

Answer Posted / guru

You can change the column data type using this query:

Alter table table_name modify column_name datatype(length)

For example:
Alter table user modify name char(30)
You can change column name using this query:

Alter table table_name change old_column_name
new_column_name datatype(length)

For example:
Alter table user change user user_name char(30)

If you want to change column name and data type in single
query, then you use this query:

Alter table table_name change old_column_name
new_column_name new_datatype(10)

For example:
Alter table user change name user_name char(30)

For more details visit,

http://www.phponwebsites.com/2013/12/mysql-change-column-name.html
(for change column name)

http://www.phponwebsites.com/2013/12/mysql-change-column-datatype.html(for
change column datatype)

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we get the number of rows affected by query?

787


What do we use to remove duplicate records while fetching a data in mysql ?

726


Is blocked because of many connection errors mysql?

637


How to decrement dates by 1 in mysql?

752


What is difference between pdo and mysqli?

731


In how many ways we can retrieve the data in the result set of MySQL using PHP? What is the difference between mysql_fetch_object and mysql_fetch_array ?

780


how you will show all records not containing the name "sonia" and the phone number '9876543210' order by the phone_number field.

714


What is offset limit?

722


How to create a table?

725


How many rows we can insert in a mysql table?

729


What is unsigned in mysql?

697


Can you tell the reasons for selecting lamp(linux, apache, mysql, php) instead of any other combination of software programs, servers, and operating system?

691


What are the advantages/disadvantages of mysql and php?

701


What is the difference between sql and mysql and oracle?

651


How do I delete a row in mysql?

718