Assuming I have the following database / tables (Fk means foreign key to said table):
Table: Brand
Table: Customer (Primary Key {CustomerId}) [Fk Brand]
Table: Address [Fk Region] [Fk Customer]
Table: Region
If I have a "CustomerId" and direct access to the database, is there a way I can loop through the database without knowing any other tables except for the table my "CustomerId" exists in?
I want to generate the sql insert statements in the correct order to re-create the entire customer structure so that anything that has a Fk to the customer and anything the customer has a Fk on, will also be re-created.
I am fine with someone just giving me a link on a "how to" to something similar. The reason I want this is because I often get a request at work saying "x customer has y issue" and sometimes without getting that exact data into a testing database it can be almost impossible to figure out as you don't want to touch the data in production. So If I can run a program that will build the customer as it exists in production, it will make my life much easier.
I am sure this must be possible using C# and or Stored Sprocs in the database.