docs: inline one-to-one relationship SQL

More direct than having to jump to the sample film database definition.
This commit is contained in:
steve-chavez
2024-10-21 14:45:53 -05:00
parent 5ca969f4b8
commit bee862c2fa
+14 -7
View File
@@ -209,18 +209,25 @@ The join table is also detected if the composite key has additional columns.
One-to-one relationships One-to-one relationships
------------------------ ------------------------
One-to-one relationships are detected in two ways. One-to-one relationships are detected in two ways. (We'll use the ``films`` and ``technical_specs`` tables from the :ref:`sample film database <erd_film>` as an example).
- When the foreign key is a primary key as specified in the :ref:`sample film database <erd_film>`. - When the foreign key is also a primary key.
- When the foreign key has a unique constraint.
.. code-block:: postgres .. code-block:: postgres
create table technical_specs( create table technical_specs(
film_id int references films(id) unique, film_id int references films(id) primary key
runtime time, -- ...
camera text, );
sound text
- Or when the foreign key has a unique constraint.
.. code-block:: postgres
create table technical_specs(
id int primary key
, film_id int references films(id) unique
-- ...
); );
.. code-block:: bash .. code-block:: bash