- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I modify an existing column's data type?
To modify an existing column’s data type, you can use MODIFY. Let us first create a table −
mysql> create table DemoTable ( ClientId varchar(100), ClientName varchar(100), ClientAge int, ClientProjectDeadline timestamp, ClientCountryName varchar(100), isMarried boolean, ClientNumber bigint ); Query OK, 0 rows affected (0.70 sec)
Check the description of table −
mysql> desc DemoTable;
This will produce the following output −
+-----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+--------------+------+-----+---------+-------+ | ClientId | varchar(100) | YES | | NULL | | | ClientName | varchar(100) | YES | | NULL | | | ClientAge | int(11) | YES | | NULL | | | ClientProjectDeadline | timestamp | YES | | NULL | | | ClientCountryName | varchar(100) | YES | | NULL | | | isMarried | tinyint(1) | YES | | NULL | | | ClientNumber | bigint(20) | YES | | NULL | | +-----------------------+--------------+------+-----+---------+-------+ 7 rows in set (0.34 sec)
Now, change the column(ClientNumber) data type bigint to varchar(20) −
mysql> alter table DemoTable modify ClientNumber varchar(20); Query OK, 0 rows affected (1.82 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again −
mysql> desc DemoTable;
This will produce the following output −
+-----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+--------------+------+-----+---------+-------+ | ClientId | varchar(100) | YES | | NULL | | | ClientName | varchar(100) | YES | | NULL | | | ClientAge | int(11) | YES | | NULL | | | ClientProjectDeadline | timestamp | YES | | NULL | | | ClientCountryName | varchar(100) | YES | | NULL | | | isMarried | tinyint(1) | YES | | NULL | | | ClientNumber | varchar(20) | YES | | NULL | | +-----------------------+--------------+------+-----+---------+-------+ 7 rows in set (0.00 sec)
Look at the above sample output, the data type has been changed from bigint to varchar(20).
- Related Articles
- How can I modify an existing MySQL column’s data type?
- How can we modify an existing MySQL event?
- How can we modify column/s of MySQL table?
- How can we modify an existing module in Java 9?
- How can I drop an existing column from a MySQL table?
- How do I change matplotlib's subplot projection of an existing axis?
- How can I change the name of an existing column from a MySQL table?
- What can another keyword be used instead of MODIFY to modify the column/s of MySQL table?
- Does SQL Server have an equivalent to MySQL's ENUM data type?
- How can we copy data with some condition/s from existing MySQL table?
- How can I set an ImageView's width and height programmatically in Android?
- How do I modify a MySQL column to allow NULL?
- How to set an element's display type with JavaScript?
- How can I move an existing MySQL event to another database?
- How to increase varchar size of an existing column in a database without breaking existing data in MySQL?

Advertisements