Inserting into multiple tables with multiple Pk/Fk relationships

UPDATE!!!

Do not use this method if you are planning on doing any bulk loading. There is a 10,000 variable limitation that is reported through the BizTalk Event Log entries but is actually a SQL Server design limitation.

image

and

image

I recently was working for a company who needed to store data coming in from the 837 claim into a database.

Experiencing many poorly designed databases to store claim data before, I create a database structure that will capture what the client was looking for, but also allow easy implementation of additional values to be captured into the database as use of this process increased. Now my goal/issue was to get BizTalk to take the 837 data and insert all of the data into the various tables.

For the purposes of this blog, I have simplified the example, but the concepts are the same.

The first thing I have done is created a psuedo837Claim schema, that looks somewhat like the 837 schema looks like. In the picture, I have marked what is repeatable.

The next thing I have done is created the database structure:

So now I need to start generating the schemas that represented the web I have just created. We will start by following Steve Kaufman's guidance here and creating an at-identity schema that we will use throughout the process. Once I have completed that, I generate the Header schema from the Header table. I select all of the columns (as I will for all but the end, but we will get to that later).

Then for the purposes of this blog, I will import the Application table. Here comes the modifications. Once I have imported the Application table, I need to import the at-identity schema, and I also need to make the Application record a Complex Type for later use. Because the prefix for the namespace is tns, the Data Structure Type needs to be tns:Application

I then add the primary key field and set the Data Type to the at-identity

After saving it, I then go back to my Header schema and import both the at-identity and the application schema

I then add a new record as a sibling to Header, and I name the new record Application (the name of the table), I choose as the Data Structure Type ns0:Application (ComplexType) and set the Max Occurs as blank, as we will not be repeating until later

I complete the process for all of the other tables, except for the tables that do not have children, and there I don't need to select the primary key field (as I will let SQLXML do that without me coding for that)

So I generate the schemas for everything and now we are getting to childless table importing, ProviderInfo for example, I don't need to add the primary key, I simply need to include the foreign key when I generate the schema

Remember that all I have to do is define the Data Structure Type as tns:ProviderInfo for the table name

When I import the InsertProviderInfoService into the InsertHeaderService schema I choose ns2:ProviderInfo and again, since it is not repeating, you can simply leave the Max and Min Occurs blank, for the repeating, you will change the max occurs to Unbounded

You continue this same pattern, adding primary keys if there are children to the table, omitting them if not.

The final output should look like this:

Delete all of the Orchestrations except the first one that has defined the Header and rename it to InsertClaimProcess and change the Typename to InsertClaimService also

Now for the mapping (finally). Create the map with the EDI input, and the header schema output. Since the Header, Application, and provider are all single instances, I hard code a, b, and c respectively into the updg:at-identity primary key and the foreign keys. For the ProviderInfo, ProviderLocation, and Subscriber, I link them all to 'c'

Since Subscriber is the first repeatable child table, I add an index from the source to the d primary key and then distribute the concatenated foreign key thru the child tables

Finishing out the relationships look like this:

 

Now all you have to do is finish the mapping and I am complete, invoke the map in the orchestration and it is complete.

 

Hope that this was as fun to do as it was to discover!

posted @ Friday, April 13, 2007 12:00 PM

Print

Comments on this entry:

 re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by dev at 2/14/2009 3:18 PM
Gravatar

Hi,

I have question on your post "Inserting into multiple tables with multiple Pk/Fk relationships"

I have very similar requirement coming up. The tables are around 100 with parent and child relationship and need to import 837 X12 data into those 100 tables for each claim.

We get 40K-50K claims every day.

The existing database is in Oracle.

Do you think if i follow your solution(as in the post) to implement Biztalk to load into those 100 table in oracle database, will it be scalable enough to load large volume?

otherwise this can be achieved better in SQL server?

Any inputs will be helpful!

Cheers!
Dev

# re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Eric at 3/23/2009 11:37 AM
Gravatar

SQL will be much faster, but then you are doing the same amt of work to load it to SQL to then go to Oracle.
I have this set up for an 837 and it works fine. XSLT is not terribly fast, but there isn't a problem in this setup regardless of the complexity.

 re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Chris Miller at 5/21/2009 10:55 AM
Gravatar

Excellent article - thank you!

Does the 10,000 local variable limitation mean that you can't use a schema with 10,000 element/attributes - or does it mean that you can't populate more than 10,000 rows * columns from a single XML message? I am not clear how local variables are used under the covers...

# re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Eric Stott at 5/21/2009 12:22 PM
Gravatar

It means that there can only be 10,000 relationships created, you can have a small schema, but the A1 that is created at the parent, and the subequent A1 values sent to children, if there are more than 10,000 of those, you hit the hard coded limitation in SQL Server. I have created a BulkXML adapter that does not have this limitation (plus it is a h#** of a lot faster than row by row inserts like the SQL Adapter does).

 re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Rajashekar at 7/1/2009 7:38 PM
Gravatar

I have scenario where I need to insert into child table only for special type of header record.
When I tried the solution provided It didn't work, since child record is blank it throws exception.

HRESULT="0x80070057" Description="Invalid Argument"
<Root xmlns:ns00="urn:schemas-microsoft-com:xml-updategram"><?MSSQLError HResult="0x80070057" Source="Microsoft OLE DB Provider for SQL Server" Description="Invalid Argument"?></Root>

Do we have a solution for this kind using UpdateGram or we need use Stored Procedure ?

Thanks,
Rajashekar

# re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Eric Stott at 7/1/2009 10:05 PM
Gravatar

You need to put a boolean that drives the creation of the table so if there is no data, there is no record created.

 re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Ian Jolly at 12/9/2009 6:32 AM
Gravatar

Hi Eric,
Thanks for article. I`m trying to achieve a similar goal but the difference is that for each table insert/update needs to call a individual stored procedure containing specific logic. Is this possible? In other words can I make calls to multiple SP's within the same request?

Kind Regards

Ian

# re: Inserting into multiple tables with multiple Pk/Fk relationships

Left by Cheap Web Hosting at 12/26/2009 10:33 AM
Gravatar

I have scenario where I need to insert into child table only for special type of header record.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 8 and type the answer here:
 

Live Comment Preview:

 
«March»
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910