

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Updating a MySQL column that contains dot (.) in its name?
If the MySQL column contains dot (.) in its name, then you need to use backticks around the column name. To understand the above concept, let us create a table. The query to create a table is as follows
mysql> create table UpdateDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> `User.FirstName.LastName` varchar(60) -> ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command.
The query is as follows
mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('John Smith'); Query OK, 1 row affected (0.14 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Carol Taylor'); Query OK, 1 row affected (0.25 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Mitchell Johnson'); Query OK, 1 row affected (0.19 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('David Brown'); Query OK, 1 row affected (0.16 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Larry Miller'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from UpdateDemo;
The following is the output
+--------+-------------------------+ | UserId | User.FirstName.LastName | +--------+-------------------------+ | 1 | John Smith | | 2 | Adam Smith | | 3 | Carol Taylor | | 4 | Mitchell Johnson | | 5 | David Brown | | 6 | Larry Miller | +--------+-------------------------+ 6 rows in set (0.00 sec)
Use backticks around the column name User.FirstName.LastName which contains (.).
The query is as follows
mysql> update UpdateDemo set `User.FirstName.LastName`='David Miller' where UserId=5; Query OK, 1 row affected (0.19 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table record once again. The row with UserId=5 is successfully updated.
The query is as follows
mysql> select *from UpdateDemo;
The following is the output
+--------+-------------------------+ | UserId | User.FirstName.LastName | +--------+-------------------------+ | 1 | John Smith | | 2 | Adam Smith | | 3 | Carol Taylor | | 4 | Mitchell Johnson | | 5 | David Miller | | 6 | Larry Miller | +--------+-------------------------+ 6 rows in set (0.00 sec)
- Related Questions & Answers
- Updating only a single column value in MySQL?
- Can we select field name in MySQL that contains an asterisk?
- Given a column name how can I find which tables in a MySQL database contain that column?
- Rename column name in MySQL?
- Fetch a specific column value (name) in MySQL
- Wildcards in column name for MySQL?
- Display distinct column name in MySQL
- How to remove a column from matrix in R by using its name?
- Find the column name that contains value greater than a desired value in each row of an R data frame.
- MySQL query to display columns name first name, last name as full name in a single column?
- Updating a record in MySQL using NodeJS
- Updating a MySQL table row column by appending a value from user defined variable?
- Updating boolean value in MySQL?
- MySQL random rows sorted by a specific column name?
- How to select a column name with spaces in MySQL?
Advertisements