Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    23

    about the relation type 1:1

    hi guys,
    I am be assailed with this relation type and trying to figure it out. I have two entities A (aid, ...) and B (bid, aid ...). for A 'aid' is the primary key, for B 'bid' is the primary key and 'aid' is the foreign key referencing A(aid). A may has 0 or 1 entity B but B must corresponds to 1 entity A, the relation between them can be described as
    A (1..1) —— (0..1)B. so I think when creating table for B, bid is not necessary, aid can be the foreign key and also the primary key. please correct me if I think wrongly.
    I have looked up for this case in a database book. it keeps the 'bid' in the table.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you think correctly

    B does not need bid, and B.aid can be both PK and FK

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    "aid" should be a key in B (the (0..1) part of the constraint). Whether you also need "bid" depends on what that attribute means in your data model. Presumably you are implying that "bid" is just surrogate key that can be dropped without losing any information. Is that right?

  4. #4
    Join Date
    Jan 2009
    Posts
    23
    yes. bid is an integer and just to identify the rows in the table

Posting Permissions

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