- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
Update column size in MySQL and increase its size?
To update the column size, you can use alter command. The syntax is as follows −
alter table yourTableName change yourColumnName yourColumnName data type;
To understand the above syntax, let us create a table. The query to create a table −
mysql> create table DataTruncated −> ( −> id int, −> Name varchar(5) −> ); Query OK, 0 rows affected (0.64 sec)
Look at the column ‘Name’ above, the column size is 5. Whenever we will give the size greater than 5 then MySQL gives the following error −
mysql> insert into DataTruncated values(101,'JohnSmith'); ERROR 1406 (22001): Data too long for column 'Name' at row 1
Now update the column size of column ‘Name’. The query is as follows −
mysql> alter table DataTruncated change Name Name varchar(200); Query OK, 0 rows affected (2.01 sec) Records: 0 Duplicates: 0 Warnings: 0
Insert the same record into the table. Now no error is visible since we updated the column size from 5 to 25 −
mysql> insert into DataTruncated values(101,'JohnSmith'); Query OK, 1 row affected (0.11 sec)
Display the records −
mysql> select *from DataTruncated;
The following is the output −
+------+-----------+ | id | Name | +------+-----------+ | 101 | JohnSmith | +------+-----------+ 1 row in set (0.00 sec)
- How to update a column of varchar type in MySQL to increase its length?
- How to increase varchar size of an existing column in a database without breaking existing data in MySQL?
- How to increase plt.title font size in Matplotlib?
- How to modify the size of column in MySQL table?
- Find size of text stored in a specific MySQL column?
- Fetch the size of a specific column values in MySQL and display the sum
- Increase the font size of a paragraph with Bootstrap
- How to increase the font size of text in Arduino IDE?
- Increase or decrease the size of a font with CSS
- How to increase the font size of a Text widget?
- Change the font / size of row and column headings in Excel
- List MySQL tables and sizes ordered by size?
- What is Grounding Conductor and How to Calculate its Size?
- How to change max_allowed_packet size in MySQL?