- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Purpose of using CHANGE command in MySQL?
The CHANGE command in MySQL is used to rename column name. Let us first create a table −
mysql> create table DemoTable796 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,Name varchar(100),StudentAge int ); Query OK, 0 rows affected (0.56 sec)
Let us check the description of table −
mysql> desc DemoTable796;
This will produce the following output −
+------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(100) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +------------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
Following is the query to use CHANGE command in MySQL −
mysql> alter table DemoTable796 change Name StudentName varchar(100); Query OK, 0 rows affected (0.29 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again −
mysql> desc DemoTable796;
This will produce the following output −
+-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(100) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
Advertisements