tags:

views:

66

answers:

3

Hi Guys;

I know that i will have to write some sort of script for this but? can you guys guive me a go ahead on hwo to do it as i havent done it before.

Thanks

+3  A: 

You can have this done for you at GenerateData. Simply specify the column names & datatypes, and how you want the data to be output (SQL statements, HTML,Excel,XML,CSV) .

alt text

p.campbell
+1. good link..
codaddict
Thanks but this and other softwares also only allow abotu 100 entries for free ... spending moeny is not an option for me rigth now as i'm a student.
Mohammad Umair
@Mohammad: the one linked here lets you gen **5000**. Do that, and just copy/paste/manipulate as you need to reach your target.
p.campbell
+1  A: 

If you want more control over the data, try something like this (in PHP):

<?php
$conn = mysql_connect(...);
$num = 100000;

$sql = 'INSERT INTO `table` (`col1`, `col2`, ...) VALUES ';
for ($i = 0; $i < $num; $i++) {
  mysql_query($sql . generate_test_values($i));
}
?>

where function generate_test_values would return a string formatted like "('val1', 'val2', ...)". If this takes a long time, you can batch them so you're not making so many db calls, e.g.:

for ($i = 0; $i < $num; $i += 10) {
  $values = array();
  for ($j = 0; $j < 10; $j++) {
    $values[] = generate_test_data($i + $j);
  }
  mysql_query($sql . join(", ", $values));
}

would only run 10000 queries, each adding 10 rows.

gmarcotte
+1  A: 

You could also use a stored procedure. Consider the following table as an example:

CREATE TABLE your_table (id int NOT NULL PRIMARY KEY AUTO_INCREMENT, val int);

Then you could add a stored procedure like this:

DELIMITER $$
CREATE PROCEDURE prepare_data()
BEGIN
  DECLARE i INT DEFAULT 100;

  WHILE i < 100000 DO
    INSERT INTO your_table (val) VALUES (i);
    SET i = i + 1;
  END WHILE;
END$$
DELIMITER ;

When you call it, you'll have 100k records:

CALL prepare_data();
Daniel Vassallo
very nice solution .. i was thinking to write a for loop for it.
Mohammad Umair