- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 only a single column value in MySQL?
Let us first create a table −
mysql> create table DemoTable770 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (0.65 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable770(Value) values(10); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable770(Value) values(90); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable770(Value) values(160); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable770(Value) values(450); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable770(Value) values(560); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable770;
This will produce the following output -
+----+-------+ | Id | Value | +----+-------+ | 1 | 10 | | 2 | 90 | | 3 | 160 | | 4 | 450 | | 5 | 560 | +----+-------+ 5 rows in set (0.00 sec)
Following is the query to update only a single column value −
mysql> update DemoTable770 set Value=Value+150 where Id=4; Query OK, 1 row affected (0.52 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the description of the view −
mysql> select *from DemoTable770;
This will produce the following output -
+----+-------+ | Id | Value | +----+-------+ | 1 | 10 | | 2 | 90 | | 3 | 160 | | 4 | 600 | | 5 | 560 | +----+-------+ 5 rows in set (0.00 sec)
Advertisements