
- 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
How to increase varchar size of an existing column in a database without breaking existing data in MySQL?
Increase the varchar size of an existing column in a database with the help of CHANGE command. The syntax is as follows −
alter table yourTableName change yourColumnName yourColumnName dataType;
Here, we are creating a table with a single column and varchar size 200 −
mysql> create table IncreaseVarcharDemo −> ( −> StudentId varchar(200) −> ); Query OK, 0 rows affected (0.60 sec)
Now insert record in the table. The query is as follows −
mysql> insert into IncreaseVarcharDemo values('John123'); Query OK, 1 row affected (0.16 sec)
Displaying all records from the table with the help of the following query −
mysql> select *from IncreaseVarcharDemo;
The following is the output −
+-----------+ | StudentId | +-----------+ | John123 | +-----------+ 1 row in set (0.00 sec)
The following is the query to increase varchar size from 200 to 1000 −
mysql> alter table IncreaseVarcharDemo change StudentId StudentId varchar(1000); Query OK, 0 rows affected (0.18 sec) Records: 0 Duplicates: 0 Warnings: 0
Now you can check the varchar size has been increased or not. The query is as follows −
mysql> desc IncreaseVarcharDemo;
The following is the output −
+-----------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------+------+-----+---------+-------+ | StudentId | varchar(1000) | YES | | NULL | | +-----------+---------------+------+-----+---------+-------+ 1 row in set (0.03 sec)
- Related Articles
- Add data to existing data in a MySQL Database?
- How to rename a column in an existing MySQL table?
- Inserting data into a new column of an already existing table in MySQL?
- Update existing column data in MySQL and remove the last string from a varchar column with strings and numbers
- How to delete a column from an existing table in a database using JDBC API?
- How can I move an existing MySQL event to another database?
- Set NOT NULL attribute to an existing column in MySQL
- Adding new enum column to an existing MySQL table?
- How can I drop an existing column from a MySQL table?
- How can we create a table from an existing MySQL table in the database?
- How to update a column of varchar type in MySQL to increase its length?
- How to call an existing function in a database using JDBC API?
- How to add column to an existing table in PostgreSQL?
- How to add a new column at the front of an existing R data frame?
- Adding characters in values for an existing int column in MySQL?

Advertisements