

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Changing Column in MySQL from int to double?
To change the column in MySQL from int to double you need to use ALTER TABLE command.
The syntax is as follows:
ALTER TABLE yourTableName modify column yourColumnName DOUBLE NOT NULL;
If you want NULL value then remove NOT NULL from the above syntax. The syntax is as follows:
ALTER TABLE yourTableName modify column yourColumnName DOUBLE;
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table IntToDoubleDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(10), -> CylinderVolume int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.63 sec)
Check the description of the table using DESC command. The syntax is as follows:
DESC yourTableName;
Apply the above query for your table to get the description of the table:
mysql> desc IntToDoubleDemo;
The following is the output:
+----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(10) | YES | | NULL | | | CylinderVolume | int(11) | YES | | NULL | | +----------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.18 sec)
Look at the above sample output, the field ‘CylinderVolume’ is a type of int. Now you can convert from int to double.
Change the column in MySQL from int to double. The query is as follows:
mysql> alter table IntToDoubleDemo MODIFY COLUMN CylinderVolume double NOT NULL; Query OK, 0 rows affected (2.79 sec) Records: 0 Duplicates: 0 Warnings: 0
Once again check the description of the table. The query is as follows:
mysql> desc IntToDoubleDemo\G
The following is the output:
*************************** 1. row *************************** Field: Id Type: int(11) Null: NO Key: PRI Default: NULL Extra: auto_increment *************************** 2. row *************************** Field: Name Type: varchar(10) Null: YES Key: Default: NULL Extra: *************************** 3. row *************************** Field: CylinderVolume Type: double Null: NO Key: Default: NULL Extra: 3 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL - changing table engine from innoDB to MyISAM?
- MySQL index on column of int type?
- Insert NULL value into INT column in MySQL?
- How to cast from VARCHAR to INT in MySQL?
- MySQL - Changing year of dates from 2020 to 2011?
- Changing data type from date to date/time in MySQL?
- Find records with double quotes in a MySQL column?
- How to select max of mixed string/int column in MySQL?
- int(5) vs. int(10) in MySQL?
- Adding characters in values for an existing int column in MySQL?
- Changing year in MySQL date?
- MySQL update a column with an int based on order?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- How to Map double to int Object with mapToInt and mapToObj in Java?