inserting data into composite primary key

  • Table vendor

    vendorid(primarykey) vendorname

    1 target

    2 med

    3 mdi

    4 cashwise

    5 walmart

    Table client

    clientid(primarykey) clientname

    1 A

    Table clientvendor

    clientid vendorid (composite primarykey)

    1 1

    1 2

    1 3

    1 4

    1 5

    Rule: 1 client has many vendors and many vendors may belong to many clients.

    I have to insert the vendorid and the clientid from the client and vendor table into clientvendor junction table. Since I have just one client; I was able to insert the records into the junction table with the help of a cross join.

    If I have another client record into the client table inserted as follows; and vendorids 2 and 3 also belong to client B;

    clientid(primarykey) clientname

    1 A

    2 B

    Could someone please let me know how would I get the following result; I must also note that I will be dealing with thousands of common vendors data between two or three clients.

    Table clientvendor

    clientid vendorid (composite primarykey)

    1 1

    1 2

    1 3

    1 4

    1 5

    2 2

    2 3

  • Please don't cross post. It just wastes peoples time and fragments replies.

    No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic957435-391-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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