best db schema

Toby A Inkster mail at tobyinkster.co.uk
Thu Feb 5 17:52:00 CET 2009


On 5 Feb 2009, at 14:33, Robin Berjon wrote:

> I was wondering if anyone here had ideas about the best DB schema  
> one can use to store RDF in an RDBMS? A lot of those I've seen seem  
> to be crazy with the self-joining, so I was wondering if there were  
> better ideas.


What I'd suggest is something like this (though the "nodes" table  
could do with more normalisation):

	CREATE TABLE nodes
	(
		node_id integer PRIMARY KEY,
		node_type varchar(1), -- 'b', 'u' or 'l'
		uri varchar,
		literal varchar,
		datatype varchar,
		lang varchar(2)
	);

	CREATE TABLE triples
	(
		subject integer REFERENCES nodes(node_id),
		predicate integer REFERENCES nodes(node_id),
		object integer REFERENCES nodes(node_id),
		graph integer REFERENCES nodes(node_id),
		PRIMARY KEY (subject, predicate, object, graph)
	);

	CREATE TABLE node_names
	(
		node_id integer REFERENCES nodes(node_id),
		graph REFERENCES nodes(node_id),
		name varchar,
		PRIMARY KEY (node_id, name)
	);

node_names, in case it's not self-explanatory records the names of  
blank nodes as they are referred to in each graph. So we could say  
that the name '_:Bob' in graph 82 referred to node 98. (Graphs are  
themselves nodes by the way.)

Oh, and 'b', 'u', 'l' is 'blank', 'uri', 'literal'.

-- 
Toby A Inkster
<mailto:mail at tobyinkster.co.uk>
<http://tobyinkster.co.uk>





More information about the Dev mailing list