Two Primary Keys

Results 1 to 2 of 2

Thread: Two Primary Keys

  1. #1
    Join Date
    Dec 1969

    Default Two Primary Keys

    I see an example of a table with two primary keys.<BR>One field is order_ID but since that can accur multiple times, the author created another field called lineItem which increments by 1 next to multiple instances of order_ID<BR><BR>ex:<BR><BR>Order_ID ----- LineItem<BR>100 ------- 1<BR>100 ------- 2<BR>101 ------- 1<BR>102 ------- 1<BR>103 ------- 1<BR>103 ------- 2<BR>104 ------- 3<BR><BR>How would I set up the lineItem field in SQL server?<BR>I just don&#039t see what command that will make lineItem start at 1 with a new order_ID.<BR><BR>Thanks,<BR><BR>Howard

  2. #2
    Join Date
    Dec 1969

    Default RE: Two Primary Keys

    Could be wrong, but <BR><BR>(1) I don&#039t think that *either* of those is a "Primary Key". A primary key *must* be unique in a table. I think that "OrderID" is a *foreign key" into another ("orders", probably) table.<BR><BR>(2) I doubt that what you see was done via SQL, alone. I would imagine that the author first created the "orders" record (in another table) and then, for each lineitem in the order (presumably as captured off some form) he creates an entry in this table.<BR><BR>Why do you presume this was all done in "raw" SQL? Seems pretty unlikely to me.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts