How to Rename column name in MySql ?
To rename a column in a MySQL table, you can use the ALTER TABLE statement along with the RENAME keyword.
Raname column name of MySQL table
Query :
ALTER TABLE tags RENAME COLUMN title TO name;
The SQL statement ALTER TABLE tags RENAME COLUMN title TO name;
is used to rename a column named title to name in the tags table.
Here's a breakdown of the statement:
ALTER TABLE tags
: Specifies the table tags that you want to modify.
RENAME COLUMN
: Indicates that you want to rename a column.
title
: Specifies the current name of the column that you want to rename.
TO name
: Specifies the new name that you want to assign to the column.
Create table statement for the tags table. You can use alter command after creating the tags table in your mysql database.
CREATE TABLE `tags` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- How to check the MySQL version
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Database connection using mySQLi with object-oriented
- How to create a new table from existing table in SQL
- Get create table Query from existing table in phpMyAdmin
- SQL query to delete all rows older than 30 days
- Create column after a column in existing table using query in MySQL
- Self join in mysql employee manager example
- Get number of connections being used by a specific user in MySQL
- Get full name of a person in SQL using function
- How to retrieve data from two tables with one SQL statement
- MySQL create procedure example
- How to show database tables in mysql using command line
- How to create function in MySQL ?
- Change existing MySQL table column id to autoincrement
- Check constraint in MySQL
- Difference between SQL and NoSQL databases
- SQL query to delete records older than 6 months
- Create Index in MySQL with example
- How to create view in MySQL database
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- How to drop function in MySQL ?
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- Create Employee table in MySQL
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint