I'm trying to learn these relationships. Is it correct as I show below that:
1) I will have a 1:0..1 relation by simply making the identity key of the parent also the identity key of the child?
2) To make it 1:1, I add an FK in parent table, connecting the two Identity columns?
Is this all there is to it? And please correct me if my wording is not exact/correct.
1:0..1
Customer(Id {PK, Identity}, Name)
CustomerAddress(CustomerId {PK, FK, Identity}, StreetName)
FK_CustomerAddress_Customer(CustomerId, Id)
1:1
Customer(Id {PK, FK, Identity}, Name)
FK_Customer_CustomerAddress(Id, CustomerId)
CustomerAddress(CustomerId {PK, FK, Identity}, Streetname)
FK_CustomerAddress_Costumer(CustomerId, Id)
EDIT1:
I believe both above was wrong, and solution is like this: (?)
1:0..1
Customer(Id {PK, Identity}, Name)
CustomerAddress(CustomerId {PK, FK, UNIQUE}, StreetName)
FK_CustomerAddress_Customer(CustomerId, Id)
A 1:1 relationship between two tables means that each tuple in each table maps to exactly one tuple in the other. This is more formally known as a Bijection. It's a limitation of SQL that for most practical purposes bijection is effectively impossible to achieve in a SQL database. That's because SQL requires each table to be updated individually and therefore there is no way to update two such tables unless you temporarily disable one of the constraints.
A 1:0/1 relationship is also known as an Surjection (your first example). Surjection is the standard behaviour of a SQL-style "FOREIGN KEY" constraint assuming nulls are not permitted. The constraint is always optional on one side of the relationship.
NOTE: The IDENTITY property isn't relevant to your example. It's the key and foreign key constraints that define the relationship.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With