How to randomly fill in a table consisting of 3 columns, columns have the following types:

  1. int(10) AUTO_INCREMENT - no need to fill it
  2. varchar(150)
  3. date

Thank you in advance!

  • @ Roman This question is better to ask on the forum [HashCode] (hashcode.ru). - Nicolas Chabanovsky

2 answers 2

If the base is in MySQL, on python you can do this (apt-get install python-mysqldb):

 import stringimport randomimport datetimeimport MySQLdbmaxlen = 250nrecords = 1000def main(): db = MySQLdb.connect(host = "127.0.0.1", user = "user_name", passwd = "user_pass", db = "test") cursor = db.cursor() for item in xrange(nrecords): name = "".join(random.choice(string.letters) for i in xrange(maxlen)) date = datetime.datetime.now() sql = "INSERT INTO TABLE1 (NAME, DATE) VALUES (\"%s\", \"%s\")" % (name, date) cursor.execute(sql) cursor.close() db.close()if __name__ == "__main__": main() 

    UPDATE table SET field = RAND ()