SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up add random data to the table

    hi.

    for debug test, i need store 200 random numbers in the database

    I obviously want to avoid insert one by one

    how i can do that? (mysql)

    i discover this, but is not what i pretend.


    Code:
    UPDATE tablename SET column1 = (rand() * 50)

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    do it with php

    pseudo-code:
    Code:
    loop=0;
    while loop < 200 {
    INSERT INTO daTable (daColumn) VALUES ( {$rand(something)} )
    loop += 1;
    }
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,058
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    You'll have to have a little bit more than just a single query to insert the data

    INSERT INTO table (col1, col2) VALUES (1, RAND()), (2, RAND()) etc but you'll still need to put a little effort in to fill it.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    did my example use single query? not it did not, i thought it was pretty clear that it should be 200 queries

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,058
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    That wasn't aimed at you... it was a reply to the OP.

    However, I also suggested a slight variation of building it into a larger query rather than 1 row per query


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •