
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to update records in a column with random numbers in MySQL?
Let us first create a table −
mysql> create table DemoTable746 ( Number int ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable746 values(100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable746 values(200); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable746 values(300); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable746 values(400); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable746;
This will produce the following output -
+--------+ | Number | +--------+ | 100 | | 200 | | 300 | | 400 | +--------+ 4 rows in set (0.00 sec)
Following is the query to update records with random number:
mysql> update DemoTable746 set Number=CAST(RAND() * 10000 AS UNSIGNED); Query OK, 4 rows affected (0.13 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable746;
This will produce the following output -
+--------+ | Number | +--------+ | 4422 | | 1350 | | 3485 | | 3371 | +--------+ 4 rows in set (0.00 sec)
- Related Articles
- How to update MySQL column with random value?
- How to update a range of records in MySQL?
- MySQL UPDATE the corresponding column with random number between 1-3?
- Select three random records with a fixed number of characters for each column value in MySQL
- Round records with numbers in MySQL
- How to select records beginning with certain numbers in MySQL?
- Find records with double quotes in a MySQL column?
- Order a column in MySQL with IP Address records?
- Order randomly in MySQL with a random value column?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- MySQL queries to update date records with NULL values
- MySQL Stored Procedure to update records with certain condition?
- MySQL update multiple records in a single query?
- A single MySQL query to update only specific records in a range without updating the entire column
- Update a MySQL column with JSON format?

Advertisements