![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Change the column name from a MySQL table with Student record?
To change the column name, use the AS keyword after the column name. Let us first create a table −
mysql> create table DemoTable ( Id int, StudentFirstNameInCollege varchar(100) ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(101,'Bob'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(102,'David'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+---------------------------+ | Id | StudentFirstNameInCollege | +------+---------------------------+ | 100 | Chris | | 101 | Bob | | 102 | David | +------+---------------------------+ 3 rows in set (0.00 sec)
Following is the query to change the name of one of the columns in MySQL using AS keyword −
mysql> select Id,StudentFirstNameInCollege AS Name from DemoTable;
This will produce the following output −
+------+-------+ | Id | Name | +------+-------+ | 100 | Chris | | 101 | Bob | | 102 | David | +------+-------+ 3 rows in set (0.00 sec)
Advertisements