Bulk insert multiple related tables

  • I have Table1 with an Id column and this is the primary key for this table.

    I have another table, Table2 which has an Id column which is a foreign key and references the primary key of Table1.

    Is there a way to bulk insert rows to both tables?

    Also can I use bulk insert if one of the columns is an Image?

    Thanks,

    -Asfar

  • I believe you can use images, though I've never tried.

    The only way you can insert two tables with bulk insert or bcp is to already build the IDs in both tables and insert them. No other good way.

  • Create view from these tables.

    Create INSTEAD OF INSERT trigger to populate tables with data from table INSERTED.

    Then just do INSERT INTO dbo.View.

    _____________
    Code for TallyGenerator

  • I have the same setup as Asfars only I am not trying a bulk insert. I am still unsure of how to do this partially because I am new to SQL Server 2005. I can't seem to find the "INSTEAD OF INSERT trigger" mentioned above. Any help or advice?

    Thanks.

  • Scott,

    If you do not bulk insert you may just use a SP that will accept data for both tables and inside your SP you insert part of the data into one of the tables and the rest into the other table. This way you don't have to use the triggers.

    The BOL for CREATE TRIGGER should give you the info on INSTEAD OF triggers.

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply