Generate Data for Column 1 depending on Column 2

I have Column 1 - Brand , Column 2 - Device. Device can have 2 entries - Pen or Pencil and Brand can have 5 entries - A,B,C,D,E.
I want to generate data in such a way that if the SQL Data Generator tool generates Pen for Column 2,then Column 1 should have data A or B or C only and if the tool generates Pencil for Column 2,then Column 1 should have D or E only.
How can these constraints be maintained?
Thanks in advance.

Answers

  • What you really have here is a key of sorts. Does the database have any referential integrity for these columns? Or do you have a source database that has this type of constraint?
  • I tried a few things. One that does work, if you have the domain mapping, is to use this python function:
    def main(config):
        penlist = ['A', 'B', 'C']
        pencillist = ['D', 'E']    
    
        if Device == 'pen' or Device == 'Pen':
                return random.choice(penlist)
        else:
                return random.choice(pencillist)
    
    I'm assuming here your colunm is Device, and this is the appropriate mapping. I did need to add a reference to my list of Python 2.7 libraries to get the random module.
Sign In or Register to comment.