Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Location
    Auckland, New Zealand
    Posts
    11

    Unanswered: Best Practice: Primary key in joing table

    hi there,

    i have the following joining table (many-to-many relationship)...

    CREATE TABLE [dbo].[products_to_products_swatch] (
    [products_to_products_swatch_id] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [product_id] [int] NOT NULL ,
    [products_swatch_id] [int] NOT NULL
    ) ON [PRIMARY]
    GO

    question: do i need to include a primary key in this table - being that it is a joing table?

    thanks
    mike

  2. #2
    Join Date
    Mar 2005
    Location
    Auckland, New Zealand
    Posts
    11
    joing table ??? i mean joining table )

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    If this is simply implementing a many-to-many join, then there is no need for a surrogate key. Just declare a composite primary key consisting of the foreign keys to both tables.
    If you are storing additional information regarding the relationship (timestamp, notes, modifier, whatever) you may want to include a surrogate key for developmental consistency with your other tables, but it is not required.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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