If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Table one to one relation expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-04, 01:44
divined divined is offline
Registered User
 
Join Date: Apr 2004
Posts: 110
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
Reply With Quote
  #2 (permalink)  
Old 12-20-04, 07:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On