
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Will extending the size of a varchar field in MySQL affect the data inside it?
If you will extend the size of a varchar field in MySQL then it won’t affect the data inside it.
Let us first create a table −
mysql> create table DemoTable( Name varchar(8) ); Query OK, 0 rows affected (1.11 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Name | +--------+ | John | | Robert | | Mike | | Sam | +--------+ 4 rows in set (0.00 sec)
Let us check the description of the table −
mysql> desc DemoTable;
This will produce the following output −
+-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | Name | varchar(8) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ 1 row in set (0.04 sec)
Let us now extend the VARCHAR size from VARCHAR(8) to VARCHAR(100) −
mysql> alter table DemoTable change Name Name varchar(100); Query OK, 4 rows affected (1.96 sec) Records: 4 Duplicates: 0 Warnings: 0
Let us check the description of the table once again −
mysql> desc DemoTable;
This will produce the following output −
+-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | Name | varchar(100) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 1 row in set (0.01 sec)
After extending the size of the varchar, the data inside it won’t get affected, but if the size is decreased then it can lead to issues.
- Related Articles
- Will MySQL work if we won’t include the size of VARCHAR while creating a new table?
- What is the MySQL VARCHAR max size?
- Getting the maximum value from a varchar field in MySQL
- Count the number of occurrences of a string in a VARCHAR field in MySQL?
- Sorting varchar field numerically in MySQL?
- Can we compare numbers in a MySQL varchar field?
- Is there a way to convert Integer field into Varchar without losing data in MySQL?
- How to increase varchar size of an existing column in a database without breaking existing data in MySQL?
- Appending data to a MySQL field that already has data in it?
- Set numbers as a varchar field and compare in MySQL
- Searching for an integer value in a varchar field in MySQL?
- MySQL query to get the max value with numeric values in varchar field?
- A soft iron bar is inserted inside a current-carrying solenoid. The magnetic field inside the solenoid:(a) will decrease (b) will increase(c) will become zero (d) will remain the same
- How much size does the VARCHAR takes- the defined size or the size of the content in SAP HANA?
- Future of E-Commerce: How Cloud Computing Will Affect It?

Advertisements