
- 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
Set all the columns of a MySQL table to a particular value with a single query
Let us first create a table −
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(40), ClientAge int, ClientCountryName varchar(40) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Chris',25,'US'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Bob',55,'UK'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('David',45,'AUS'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Bob | 55 | UK | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)
Here is the query to set all the columns of a MySQL table to a particular value −
mysql> update DemoTable set ClientName='Sam',ClientAge=48,ClientCountryName='AUS' where ClientId=2; Query OK, 1 row affected (0.22 sec) Rows matched : 1 Changed : 1 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Sam | 48 | AUS | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Update two columns with a single MySQL query
- MySQL query to get the highest value from a single row with multiple columns
- MySQL query to select all the records only from a specific column of a table with multiple columns
- Insert all the values in a table with a single MySQL query separating records by comma
- How to set all values in a single column MySQL Query?
- How to update all the entries except a single value in a particular column using MySQL?
- Concatenate all the columns in a single new column with MySQL
- Change multiple columns in a single MySQL query?
- Selecting a value in custom order from another column in a MySQL table with a single query
- MySQL query to sort multiple columns together in a single query
- Insert multiple values in a temporary table with a single MySQL query?
- Delete records from a MySQL table with IN() in a single query
- A single MySQL query to insert records (not all) in the second table from the first table
- How to sort multiple columns with a single query?
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
Advertisements