Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    110

    Unanswered: Table one to one relation expression

    Hello everybody

    Suppose I have two related tables. The relation is only one to one. That means that only a single record of the first table can be referenced via a foreign key in the second. Can I express such a thing using database constraints or do I have to make my checks in code?

    thx, in advance

    George Papadopoulos

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    your comment "only a single record of the first table can be referenced via a foreign key in the second" is true for one-to-many tables as well

    in a one-to-one relationship, at most one record of the second table can have a foreign key referencing any single record in the first table

    for mysql, use innodb tables in order to get foreign key support

    to restrict the relationship to one-to-one, you would use a CHECK constraint, and i don't think mysql supports it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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