EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials MariaDB Tutorial MariaDB rename column
Secondary Sidebar
MariaDB Tutorial
  • MariaDB
    • MariaDB Versions
    • MariaDB? list users
    • MariaDB Commands
    • MariaDB odbc
    • MariaDB Workbench
    • MariaDB for windows
    • MariaDB Server
    • MariaDB? Data Types
    • MariaDB? boolean
    • MariaDB phpMyAdmin
    • MariaDB Mysqldump
    • MariaDB Java Connector
    • MariaDB insert
    • MariaDB UPDATE
    • MariaDB? rename column
    • MariaDB AUTO_INCREMENT
    • MariaDB Timezone
    • MariaDB GROUP_CONCAT
    • MariaDB wait_timeout
    • MariaDB MaxScale
    • MariaDB? with
    • MariaDB GUI
    • MariaDB? create?table
    • MariaDB? SHOW TABLES
    • MariaDB alter table
    • MariaDB List Tables
    • MariaDB JSON Functions
    • MariaDB Foreign Key
    • MariaDB? trigger
    • MariaDB Grant All Privileges
    • MariaDB Select Database
    • MariaDB? create database
    • MariaDB Delete Database
    • MariaDB Join
    • MariaDB JSON
    • MariaDB? show databases
    • MariaDB List Databases
    • MariaDB Functions
    • MariaDB? TIMESTAMP
    • MariaDB create user
    • MariaDB add user
    • MariaDB Max Connections
    • MariaDB show users
    • MariaDB Delete User
    • MariaDB? change user password
    • MariaDB? change root password
    • MariaDB reset root password
    • MariaDB IF
    • MariaDB bind-address
    • MariaDB Transaction
    • MariaDB Cluster
    • MariaDB Logs
    • MariaDB Encryption
    • MariaDB? backup
    • MariaDB Replication
    • MariaDB max_allowed_packet
    • MariaDB? performance tuning
    • MariaDB export database
    • MariaDB? import SQL

MariaDB rename column

MariaDB rename column

Introduction to MariaDB rename column

MariaDB provides different types of commands to the user; the rename column name is the one type command. We want to change the structure of the existing table that means the user needs to change the column name of the table. At that time we use the alter table command to change the specified column name. By using alter table command we can perform different operations such as add column and delete column etc. When we need to change the column name of the specified table that means we executing the ALTER TABLE statement but it requires at least ALTER privilege for the database or table. The alter table comes under the DDL language. In this topic, we are going to learn about the MariaDB rename column.

Syntax

alter table table_name change existing colm name colm definition new colm name with data types;

Explanation

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In the above syntax, we used the alter table command to rename the column name; here table_name is used for the specified table name that we need to alter. After that we write the change keyword to rename the column name followed by the existing column name that we need to rename, here we use the existing column name with a new column name with the data type that we need to update.

How to rename a column in MariaDB?

Let’s see how the rename column name works in MariaDB as follows.

The first user must have alter table privileges to rename the column name from the specified table.

For the rename column, we use alter table command, by using alter table command we can change the structure of the specified table.  First, we need to see the structure table that we need to alter by using the command. Then we use the above syntax to rename the column name with column definition. When clauses are used IF EXISTS and IF NOT EXISTS, queries will not show the error message when the condition is triggered for that clause. It just shows a warning message and the alter command will move on to the next clause in the statement.

The change is used to rename the column from the specified table. In this clause, we can also change the data type of column, and in this clause, the data type is mandatory even if we need to keep the existing data type. Another most important function of the change clause is that we can place the column in a different position by using the first or after column clause as per our requirement.

Another way to rename columns is that rename column clause; it is the simplest way to rename column names. We cannot rename column names that are already present in the table. The rename column clause can be used only to rename column names, if we need more functions such as changing the data definition and position of the column at that time we need the change clause instead of rename column clause.

Examples

Let’s see the different examples of rename columns as follows.

First, see the table structure by using the following statement.

describe emp;

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,697 ratings)

Explanation

In the above statement, we use describe command to see the detailed structure of the emp table. It is useful to see all the column names with its definition. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB rename column output 1

After that, the user can select any column name that we need to rename as follows.

alter table emp change emp_id id int;

Explanation

In the above example, we use the alter table command to rename the column name, here emp the specified table name that we need to alter, after that we use the change keyword to rename the column name. In this example, emp_id is the old column name that we need to rename by id with data type integer as shown in the above statement. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB rename column output 2

Now see the updated column name by using the following statement as follows.

select * from emp;

Explanation

In the above example, we use a select clause to see the whole table, see here we successfully rename the column name that is we rename the column name emp_id to id with the integer data type. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB rename column output 3

We can also rename column names by using the rename keyword as follows.

Syntax

alter table table_name rename colm existing column name to new column name;

Explanation

In the above syntax, we used alter table command to rename the column name, here the table name means a specified table that we need to alter, after that we use rename keyword to update the column name. In the above syntax existing column name means the old column name that we need to rename by the new column name.

Example

alter table emp rename column emp_name to name;

Explanation

In the above example, we use the alter table command to update the emp table, in this example, we use rename column keyword instead of change the keyword to rename column name. Here we rename emp_name to name as shown in the above statement. . The final output of the show databases query we illustrate by using the following snapshot.

output 4

Now see the updated column name by using the following statement.

select * from emp;

Explanation

In the above example, we use a select clause to see the whole table, see here we successfully rename the column name by using rename column keyword that is we rename the column name emp_name to name with the varchar data type. The final output of the show databases queries we illustrate by using the following snapshot.

output 5

Let’s see some other examples of rename columns as follows.

Suppose we need to change the emp_dept column name and also we need to place after emp_address at that time we can use the following statement.

alter table emp change emp_dept dept varchar(250) after emp_address;

Explanation

In the above example, we use the change clause with the after option. The final output of the show databases query we illustrate by using the following snapshot

output 6

Conclusion

We hope from this article you have understood about the MariaDB rename column. From this article, we have learned the basic syntax of the rename column and we also see different example rename columns. From this article, we learned how and when we use MariaDB rename columns.

Recommended Articles

This is a guide to MariaDB rename column. Here we discuss the basic syntax of the rename column and we also see different example rename columns. You may also have a look at the following articles to learn more –

  1. MariaDB Commands
  2. MariaDB UPDATE
  3. MariaDB Grant All Privileges
  4. MariaDB Foreign Key
Popular Course in this category
SQL Training Program (7 Courses, 8+ Projects)
  7 Online Courses |  8 Hands-on Projects |  73+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more