loading...

Using Python to create SqlServer tables with random schema

mesmacosta profile image Marcelo Costa Updated on ・1 min read

Having a large amount of test data sometimes take a lot of effort, and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for SQLServer.

Environment

Activate your virtualenv
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
Install the requirements for the metadata generator
pip install -r requirements.txt
Install ODBC Driver 17 for SQL Server

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

Code

Execution

export SQLSERVER_SERVER=127.0.0.1
export SQLSERVER_USERNAME=sqlserver
export SQLSERVER_PASSWORD=sqlserver_pwd
export SQLSERVER_DATABASE=test_db

python metadata_generator.py \
--sqlserver-host=$SQLSERVER_SERVER \ 
--sqlserver-user=$SQLSERVER_USERNAME \
--sqlserver-pass=$SQLSERVER_PASSWORD \ 
--sqlserver-database=$SQLSERVER_DATABASE

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!

Posted on by:

mesmacosta profile

Marcelo Costa

@mesmacosta

senior software engineer & google cloud certified architect and data engineer @ ciandt.com

Discussion

pic
Editor guide