Skip to content

Instantly share code, notes, and snippets.

@BalicantaYao
Created August 7, 2014 02:48
Show Gist options
  • Save BalicantaYao/466c4a9ba565bc38f8f3 to your computer and use it in GitHub Desktop.
Save BalicantaYao/466c4a9ba565bc38f8f3 to your computer and use it in GitHub Desktop.
from random import randint
import pyodbc
from datetime import datetime
import random
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=xxxxx;DATABASE=POC_HOUSEKEEPING;UID=xxxxx;PWD=xxxxxx')
cursor = cnxn.cursor()
for num in range(0,1000100):
try:
version = randint(1,1)
treeNode = randint(1,1000000)
values = randint(2,9)
level = randint(1,5)
year = random.choice(range(1950, 2000))
month = random.choice(range(1, 12))
day = random.choice(range(1, 28))
birthDate = datetime(year, month, day)
cursor.execute("INSERT INTO TS_4_3(VERSIONID, TREENODEID, TARGETDATE, VALUE, UPDATEDAT, UPDATEDBY, CHANGEDSTATUSCODE, LEVELNUM) VALUES (?, ?, ?, ?, '', 0, 0, ?)"
, version, treeNode, birthDate, values, level)
cnxn.commit()
except pyodbc.IntegrityError:
print "Repeat Data"
pass
cursor.close()
cnxn.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment