Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

updating normalized db with referential integrity

TCaptainTCaptain Member Posts: 20
Hi,

I'm hoping this is a simple(ish) question. I'm new to programming on a SQL-Server.

I've got a VB.Net app that is importing/formatting records from a text file.

I would like to output these records to a main table but the design of it is normalized.

For instance in the main table we have instead of a product-type, we have a foreign key to a product table. The records I want to import have the actual product type and I'm guessing can't be imported directly.

What I'm wondering is, do I have to do all the coding, ie: before importing each record, check that the product type actually exists (if not add it to the product table) then change the product type in the record to be imported to the correct foreign key THEN import?

Does that make sense? Or is there an easier way that I don't know about (and what I don't know could fill a library at this point)

Comments

  • AnnadiAnnadi Member Posts: 2
    : Hi,
    :
    : I'm hoping this is a simple(ish) question. I'm new to programming on a SQL-Server.
    :
    : I've got a VB.Net app that is importing/formatting records from a text file.
    :
    : I would like to output these records to a main table but the design of it is normalized.
    :
    : For instance in the main table we have instead of a product-type, we have a foreign key to a product table. The records I want to import have the actual product type and I'm guessing can't be imported directly.
    :
    : What I'm wondering is, do I have to do all the coding, ie: before importing each record, check that the product type actually exists (if not add it to the product table) then change the product type in the record to be imported to the correct foreign key THEN import?
    :
    : Does that make sense? Or is there an easier way that I don't know about (and what I don't know could fill a library at this point)
    :

  • AnnadiAnnadi Member Posts: 2
    : : Hi,
    : :
    : : I'm hoping this is a simple(ish) question. I'm new to programming on a SQL-Server.
    : :
    : : I've got a VB.Net app that is importing/formatting records from a text file.
    : :
    : : I would like to output these records to a main table but the design of it is normalized.
    : :
    : : For instance in the main table we have instead of a product-type, we have a foreign key to a product table. The records I want to import have the actual product type and I'm guessing can't be imported directly.
    : :
    : : What I'm wondering is, do I have to do all the coding, ie: before importing each record, check that the product type actually exists (if not add it to the product table) then change the product type in the record to be imported to the correct foreign key THEN import?
    : :
    : : Does that make sense? Or is there an easier way that I don't know about (and what I don't know could fill a library at this point)
    : :
    :
    :



    I don't know how could this help you. You need not to look at product type and inserting them into parent table manually. If it is a one time job or doesn't effect you any time do the following two steps.
    1. Drop the forien key relationship.
    2. Run your job
    3. Select distinct product types from original table
    4. insert these back to your parent table.
    5. Create the relation ship.

    It is even the good idea if you start the transaction and make sure every thing went very well. Hope this help you.

    Thanks
    Annadi Srinivas
Sign In or Register to comment.