All the column attributes might not be available to the application for renaming.However, this comes with a few disadvantages. Notice that you can also change the data type of the column along with the name. ALTER TABLE table_nameĬHANGE COLUMN old_column_name new_column_name Data Type You can use the following syntax to change the name of the column using the CHANGE COLUMN statement. You can also use the CHANGE COLUMN command to rename a column in MySQL. MySQL RENAME COLUMN using CHANGE statement ALTER TABLE StudentsĪfter successful completion of the above statement, let’s check the table using the SELECT statement.įrom the above output, you can notice that the name of the student_age column changed to age and the name of the student_email column changed to only email. In the below example, we will change the column name student_age to age and student_email to email. Now, let us take an example of changing multiple columns in a single statement. ALTER TABLE StudentsĪs you can see from the above image that the name of the roll_no has been changed to the id successfully. We can do this using the following statement. Suppose, we want to change the name of the column roll_no to id without changing the datatype. Suppose, we have a Students table with the following data. Let’s understand the concept of renaming columns with the help of a few examples. Here, you need to specify each RENAME COLUMN statement separated by comma( ,). RENAME COLUMN old_column_name2 TO new_column_name2, RENAME COLUMN old_column_name1 TO new_column_name1, Below is the syntax: ALTER TABLE table_name You can also change the name of multiple columns in a single statement. Second, specify the name of the old column name after the RENAME COLUMN keywords.Īnd Finally, provide the new column name after the TO keyword. RENAME COLUMN old_column_name TO new_column_name įirst, specify the name of the table whose column you are going to rename after the ALTER TABLE keywords. This is the commonly used command to change a column name.īelow is the basic syntax of renaming a column in MySQL. MySQL RENAME COLUMN using RENAME statement You can rename a column name in MySQL in two ways: This command is used along with the ALTER TABLE statement. MySQL RENAME COLUMN is used to change the column name of a MySQL table. MySQL allows us to modify its objects using just a few commands. Sometimes we may need to change a column name of a MySQL table. Summary: in this tutorial, you will learn how to rename a column of a table using MySQL RENAME COLUMN and CHANGE COLUMN statements with examples.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |