<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Tags: Database schemas</title>
	<atom:link href="http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html</link>
	<description>Philipp Kellers weblog</description>
	<lastBuildDate>Mon, 06 Sep 2010 14:21:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Sean Macdonald</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133658</link>
		<dc:creator>Sean Macdonald</dc:creator>
		<pubDate>Fri, 06 Aug 2010 10:34:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133658</guid>
		<description>What if The primary index on the Tags table was the tag itself? So it would look like this

Tags
----
Tag
PostID

Posts
----
PostID
Post

QUERY
-----
SELECT * FROM Posts WHERE PostID IN (SELECT PostID FROM Tags WHERE Tag = &#039;$tag1&#039; OR Tag = &#039;$tag2&#039;)</description>
		<content:encoded><![CDATA[<p>What if The primary index on the Tags table was the tag itself? So it would look like this</p>
<p>Tags<br />
&#8212;-<br />
Tag<br />
PostID</p>
<p>Posts<br />
&#8212;-<br />
PostID<br />
Post</p>
<p>QUERY<br />
&#8212;&#8211;<br />
SELECT * FROM Posts WHERE PostID IN (SELECT PostID FROM Tags WHERE Tag = &#8216;$tag1&#8242; OR Tag = &#8216;$tag2&#8242;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL Lion</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133657</link>
		<dc:creator>SQL Lion</dc:creator>
		<pubDate>Tue, 03 Aug 2010 06:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133657</guid>
		<description>Very Nice post, quiet informative.	
Database designing problems being the buzzwords these days, one of the most common designing mistakes is the “Poor Planning / Architecture” of the database or mart. Follow the link to know more…
http://www.sqllion.com/2010/08/database-design-and-modeling-i/</description>
		<content:encoded><![CDATA[<p>Very Nice post, quiet informative.<br />
Database designing problems being the buzzwords these days, one of the most common designing mistakes is the “Poor Planning / Architecture” of the database or mart. Follow the link to know more…<br />
<a href="http://www.sqllion.com/2010/08/database-design-and-modeling-i/" rel="nofollow">http://www.sqllion.com/2010/08/database-design-and-modeling-i/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sahan</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133638</link>
		<dc:creator>Sahan</dc:creator>
		<pubDate>Wed, 30 Jun 2010 09:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133638</guid>
		<description>Thanks a ton, searching for this..</description>
		<content:encoded><![CDATA[<p>Thanks a ton, searching for this..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jules Manson</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133627</link>
		<dc:creator>Jules Manson</dc:creator>
		<pubDate>Fri, 21 May 2010 07:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133627</guid>
		<description>This is by far the best article on the world wide web that not only illustrates in clear concise language how to implement tags three different ways but also gives real world easy to follow examples and illustrations. My hat&#039;s off to you sir. You deserve all the accolades endowed to you by your readers.</description>
		<content:encoded><![CDATA[<p>This is by far the best article on the world wide web that not only illustrates in clear concise language how to implement tags three different ways but also gives real world easy to follow examples and illustrations. My hat&#8217;s off to you sir. You deserve all the accolades endowed to you by your readers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KodeZilla</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133608</link>
		<dc:creator>KodeZilla</dc:creator>
		<pubDate>Fri, 26 Mar 2010 19:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133608</guid>
		<description>Here&#039;s how one might do this with Postgres:
The REFERENCES on TMAP address the &quot;orphans&quot; issues when deleting records. 

Big Upz to the MySQL wiki for the tips - ironic huh?
http://forge.mysql.com/wiki/TagSchema#Toxi


CREATE TABLE links (
    l_id SERIAL,
    title varchar(55),
    url varchar(255),
    description varchar(300),
    CONSTRAINT &quot;links_pkey&quot; PRIMARY KEY(&quot;l_id&quot;)        
);


CREATE TABLE tmap (
    l_id integer REFERENCES links ON DELETE CASCADE,
    t_id integer REFERENCES tags,
    PRIMARY KEY (l_id, t_id)
);

CREATE INDEX tag_id_idx ON tmap (t_id);

CREATE TABLE tags (
    t_id SERIAL,
    tag varchar(30) UNIQUE,
    CONSTRAINT &quot;tags_pkey&quot; PRIMARY KEY(&quot;t_id&quot;)        
);

/////////////////////////////////

// grab data for a TAG cloud
SELECT tag, COUNT(*) as count
FROM tmap i2t
INNER JOIN tags t
ON i2t.t_id = t.t_id
GROUP BY tag;


// grab data for links tagged with any of the 3 tags
SELECT tmap.l_id
FROM tmap 
INNER JOIN tags t
ON tmap.t_id = t.t_id
WHERE t.tag IN (&#039;transcripts&#039;,&#039;registration&#039;,&#039;courses&#039;)
GROUP BY tmap.l_id;

// grab data for links tagged with all three tags being searched for
SELECT i2t3.l_id
FROM tags t1 CROSS JOIN tags t2 CROSS JOIN tags t3
INNER JOIN tmap i2t1
ON t1.t_id = i2t1.t_id
INNER JOIN tmap i2t2
ON i2t1.l_id = i2t2.l_id AND i2t2.t_id = t2.t_id
INNER JOIN tmap i2t3
ON i2t2.l_id = i2t3.l_id AND i2t3.t_id = t3.t_id
WHERE t1.tag = &#039;transcripts&#039;
AND t2.tag = &#039;registration&#039;
AND t3.tag = &#039;courses&#039;;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s how one might do this with Postgres:<br />
The REFERENCES on TMAP address the &#8220;orphans&#8221; issues when deleting records. </p>
<p>Big Upz to the MySQL wiki for the tips &#8211; ironic huh?<br />
<a href="http://forge.mysql.com/wiki/TagSchema#Toxi" rel="nofollow">http://forge.mysql.com/wiki/TagSchema#Toxi</a></p>
<p>CREATE TABLE links (<br />
    l_id SERIAL,<br />
    title varchar(55),<br />
    url varchar(255),<br />
    description varchar(300),<br />
    CONSTRAINT &#8220;links_pkey&#8221; PRIMARY KEY(&#8220;l_id&#8221;)<br />
);</p>
<p>CREATE TABLE tmap (<br />
    l_id integer REFERENCES links ON DELETE CASCADE,<br />
    t_id integer REFERENCES tags,<br />
    PRIMARY KEY (l_id, t_id)<br />
);</p>
<p>CREATE INDEX tag_id_idx ON tmap (t_id);</p>
<p>CREATE TABLE tags (<br />
    t_id SERIAL,<br />
    tag varchar(30) UNIQUE,<br />
    CONSTRAINT &#8220;tags_pkey&#8221; PRIMARY KEY(&#8220;t_id&#8221;)<br />
);</p>
<p>/////////////////////////////////</p>
<p>// grab data for a TAG cloud<br />
SELECT tag, COUNT(*) as count<br />
FROM tmap i2t<br />
INNER JOIN tags t<br />
ON i2t.t_id = t.t_id<br />
GROUP BY tag;</p>
<p>// grab data for links tagged with any of the 3 tags<br />
SELECT tmap.l_id<br />
FROM tmap<br />
INNER JOIN tags t<br />
ON tmap.t_id = t.t_id<br />
WHERE t.tag IN (&#8216;transcripts&#8217;,'registration&#8217;,'courses&#8217;)<br />
GROUP BY tmap.l_id;</p>
<p>// grab data for links tagged with all three tags being searched for<br />
SELECT i2t3.l_id<br />
FROM tags t1 CROSS JOIN tags t2 CROSS JOIN tags t3<br />
INNER JOIN tmap i2t1<br />
ON t1.t_id = i2t1.t_id<br />
INNER JOIN tmap i2t2<br />
ON i2t1.l_id = i2t2.l_id AND i2t2.t_id = t2.t_id<br />
INNER JOIN tmap i2t3<br />
ON i2t2.l_id = i2t3.l_id AND i2t3.t_id = t3.t_id<br />
WHERE t1.tag = &#8216;transcripts&#8217;<br />
AND t2.tag = &#8216;registration&#8217;<br />
AND t3.tag = &#8216;courses&#8217;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hamish</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133604</link>
		<dc:creator>Hamish</dc:creator>
		<pubDate>Thu, 18 Mar 2010 01:25:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133604</guid>
		<description>Just been reading this good introduction to faceted classification:

http://www.miskatonic.org/library/facet-web-howto.html

I hope someone else finds it useful.</description>
		<content:encoded><![CDATA[<p>Just been reading this good introduction to faceted classification:</p>
<p><a href="http://www.miskatonic.org/library/facet-web-howto.html" rel="nofollow">http://www.miskatonic.org/library/facet-web-howto.html</a></p>
<p>I hope someone else finds it useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hamish</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-133603</link>
		<dc:creator>Hamish</dc:creator>
		<pubDate>Thu, 18 Mar 2010 00:43:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-133603</guid>
		<description>Some good discussion and sharing of ideas in these comments.

I never even considered anything other than a relational 3 table schema. The system will be 99% selects so I suppose that&#039;s best anyway:
I&#039;m making an e-commerce site.. Tags would only be added when new products were added (no user contributions).

I&#039;m considering using tags rather than categories because the categories aren&#039;t forming a nice hierarchy.
Now I&#039;m going to look into hierarchical tags systems.</description>
		<content:encoded><![CDATA[<p>Some good discussion and sharing of ideas in these comments.</p>
<p>I never even considered anything other than a relational 3 table schema. The system will be 99% selects so I suppose that&#8217;s best anyway:<br />
I&#8217;m making an e-commerce site.. Tags would only be added when new products were added (no user contributions).</p>
<p>I&#8217;m considering using tags rather than categories because the categories aren&#8217;t forming a nice hierarchy.<br />
Now I&#8217;m going to look into hierarchical tags systems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: turd</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-130778</link>
		<dc:creator>turd</dc:creator>
		<pubDate>Wed, 07 Oct 2009 23:32:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-130778</guid>
		<description>this is very helpful - concise and well written.

THANKS!</description>
		<content:encoded><![CDATA[<p>this is very helpful &#8211; concise and well written.</p>
<p>THANKS!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tozetre</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-130776</link>
		<dc:creator>Tozetre</dc:creator>
		<pubDate>Wed, 30 Sep 2009 17:49:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-130776</guid>
		<description>I was checking Google to see if there were any better solutions than an intersection table (Toxi), and found this. Good article, if not precisely what I was looking for.

One thing I did notice that you might care about is your disadvantage for Toxi&#039;s schema;
&quot;When altering or deleting bookmarks you can end up with tag-orphans.&quot;
This isn&#039;t the case if you use foreign keys (which Phillip Keller implements above), and if you add ON DELETE CASCADE to your reference clause any deletion of tags or items will also delete references to it in the intersection table- for better or worse.</description>
		<content:encoded><![CDATA[<p>I was checking Google to see if there were any better solutions than an intersection table (Toxi), and found this. Good article, if not precisely what I was looking for.</p>
<p>One thing I did notice that you might care about is your disadvantage for Toxi&#8217;s schema;<br />
&#8220;When altering or deleting bookmarks you can end up with tag-orphans.&#8221;<br />
This isn&#8217;t the case if you use foreign keys (which Phillip Keller implements above), and if you add ON DELETE CASCADE to your reference clause any deletion of tags or items will also delete references to it in the intersection table- for better or worse.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marwan</title>
		<link>http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html/comment-page-2#comment-130775</link>
		<dc:creator>Marwan</dc:creator>
		<pubDate>Sun, 27 Sep 2009 17:13:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html#comment-130775</guid>
		<description>You have help me build this site! http://www.TagThis.com thanks for the article! TagThis is a tag based search and suggestion engine that gives you tailor made results. it is still in its infancy. would greatly appreciate any feedback if you have time to check it out! cheers</description>
		<content:encoded><![CDATA[<p>You have help me build this site! <a href="http://www.TagThis.com" rel="nofollow">http://www.TagThis.com</a> thanks for the article! TagThis is a tag based search and suggestion engine that gives you tailor made results. it is still in its infancy. would greatly appreciate any feedback if you have time to check it out! cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>
