mnesia foreign keys

Rudolph van Graan rvg@REDACTED
Mon Jan 19 09:03:58 CET 2004


Hi all,

I am thinking of how to get mnesia to enforce foreign key relationships 
in our database. I.e. to get some key-violation when you delete a 
record on which another record in the same or another table depends.

Looking at the Mnesia user's guide, this section seems to imply that 
such functionality already exists. Can someone explain to me how to use 
this? Is it possible to use this foreign key mechanism for what we 
need? I think I once read that Ulf Wiger had written some Relational DB 
library for mnesia?

Regards,

Rudolph van Graan

Pattern Matched Technologies

rvg@REDACTED
Mobile: +27 11 82 905 7496
Fax:	     +27 12 667 5342

5.3.2 Fragmentation Properties

There is a table property called frag_properties and may be read with 
mnesia:table_info(Tab, frag_properties). The fragmentation properties 
is a list of tagged tuples with the arity 2. By default the list is 
empty, but when it is non-empty it triggers Mnesia to regard the table 
as fragmented. The fragmentation properties are:
<snip>

foreign_key
     the foreign key.
foreigners
     all other tables that refers to this table in their foreign key.

{foreign_key, ForeignKey}
ForeignKey may either be the atom undefined or the tuple {ForeignTab, 
Attr}, where Attr denotes an attribute which should be interpreted as a 
key in another fragmented table named ForeignTab. Mnesia will ensure 
that the number of fragments in this table and in the foreign table are 
always the same. When fragments are added or deleted Mnesia will 
automatically propagate the operation to all fragmented tables that has 
a foreign key referring to this table. Instead of using the record key 
to determine which fragment to access, the value of the Attr field is 
used. This feature makes it possible to automatically co-locate records 
in different tables to the same node. foreign_key defaults to 
undefined. However if the foreign key is set to something else it will 
cause the default values of the other fragmentation properties to be 
the same values as the actual fragmentation properties of the foreign 
table.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4124 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040119/c9139c36/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2112 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040119/c9139c36/attachment-0001.bin>


More information about the erlang-questions mailing list