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 retrieve data from two tables with one SQL statement
- How to show database tables in mysql using command line
- Database connection using mySQLi with object-oriented
- Get comma separated ids from table using MySQL
- How to create view in MySQL database
- How to create a new table from existing table in SQL
- SQL query to delete records older than 6 months
- Check constraint in MySQL
- SQL query to delete all rows older than 30 days
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Insert multiple rows in a single MySQL query
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- How to create function in MySQL ?
- How to get yesterday's date in MySQL ?
- Difference between SQL and NoSQL databases
- How to get a list of MySQL views?
- Create column after a column in existing table using query in MySQL
- Drop foreign id column (user_id) in MySQL
- Get number of connections being used by a specific user in MySQL
- How to get the list of all constraints in MySQL database
- Create Employee table in MySQL
- Change existing MySQL table column id to autoincrement
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to drop function in MySQL ?
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint